Skip to content

Commit

Permalink
feat: add action output (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoieni authored Apr 28, 2024
1 parent 1dea079 commit 35a0061
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 5 deletions.
57 changes: 56 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test
on:
push:
branches:
- 'main'
- "main"
paths-ignore:
- "**.md"
pull_request:
Expand All @@ -28,8 +28,63 @@ jobs:
git commit -m "first commit"
git remote add origin https://github.com/Test/release-plz-test.git
- name: Run release-plz
id: release-plz
uses: ./ # Uses an action in the root directory
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
project_manifest: .github/workflows/marco-test-one/Cargo.toml
- name: Assert release
env:
RELEASES: ${{ steps.release-plz.outputs.releases }}
PRS: ${{ steps.release-plz.outputs.prs }}
PR: ${{ steps.release-plz.outputs.pr }}
PRS_CREATED: ${{ steps.release-plz.outputs.prs_created }}
RELEASES_CREATED: ${{ steps.release-plz.outputs.releases_created }}
run: |
set -e
echo "releases: $RELEASES"
echo "prs: $PRS"
echo "pr: $PR"
echo "prs_created: $PRS_CREATED"
echo "releases_created: $RELEASES_CREATED"
releases_length=$(echo "$RELEASES" | jq 'length')
echo "releases_length: $releases_length"
if [ "$releases_length" != "1" ]; then
echo "too many releases"
exit 1
fi
release_version=$(echo "$RELEASES" | jq -r '.[0].version')
echo "release_version: $release_version"
if [ "$release_version" != "0.1.0" ]; then
echo "bad version"
exit 1
fi
echo ${{ fromJSON(steps.release-plz.outputs.releases) }}
if [ "$release_version" != ${{ fromJSON(steps.release-plz.outputs.releases)[0].version }} ]; then
echo "bad version (fromJSON)"
exit 1
fi
release_tag=$(echo "$RELEASES" | jq -r '.[0].tag')
echo "release_tag: $release_tag"
if [ "$release_tag" != "v0.1.0" ]; then
echo "bad tag"
exit 1
fi
release_package_name=$(echo "$RELEASES" | jq -r '.[0].package_name')
echo "release_package_name: $release_package_name"
if [ "$release_package_name" != "marco-test-one" ]; then
echo "bad package name"
exit 1
fi
prs_length=$(echo "$PRS" | jq 'length')
echo "prs_length: $prs_length"
if [ "$prs_length" != "0" ]; then
echo "too many prs"
exit 1
fi
52 changes: 48 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ inputs:
description: "Release-plz version to use. It must be an existing git tag name. For example `release-plz-v0.2.45`. (Default: `latest`)."
default: "release-plz-v0.3.63"
required: false
outputs:
# Useful for when https://github.com/MarcoIeni/release-plz/issues/1029 is implemented.
# For now, it just returns an array with `pr` in it.
prs:
description: "The release PRs opened by release-plz. (Not useful for now. Use `pr` instead)"
value: ${{ steps.release-plz.outputs.prs }}
pr:
description: "The release PR opened by release-plz."
value: ${{ steps.release-plz.outputs.pr }}
releases:
description: "The JSON output of the `release` command."
value: ${{ steps.release-plz.outputs.releases }}
prs_created:
description: "Whether release-plz created any release PR."
value: ${{ steps.release-plz.outputs.prs_created }}
releases_created:
description: "Whether release-plz released any package."
value: ${{ steps.release-plz.outputs.releases_created }}
branding:
icon: "zap"
color: "yellow"
Expand All @@ -43,6 +61,7 @@ runs:
- name: Configure git user from GitHub token
uses: MarcoIeni/[email protected]
- name: Run release-plz
id: release-plz
shell: bash
run: |
if [[ -n "${{ inputs.config }}" ]]
Expand Down Expand Up @@ -75,20 +94,45 @@ runs:
if [[ -z "${{ inputs.command }}" || "${{ inputs.command }}" == "release-pr" ]]
then
echo "-- Running release-plz release-pr --"
release-plz release-pr\
release_pr_output=$(release-plz release-pr\
--git-token ${GITHUB_TOKEN}\
--repo-url https://github.com/${GITHUB_REPOSITORY}\
${CONFIG_PATH}\
${ALT_REGISTRY}\
${MANIFEST_PATH}
${MANIFEST_PATH}\
-o json)
echo "release_pr_output: $release_pr_output"
prs=$(echo $release_pr_output | jq -c .prs)
echo "prs=$prs" >> "$GITHUB_OUTPUT"
prs_length=$(echo "$prs" | jq 'length')
if [ "$prs_length" != "0" ]; then
prs_created=true
first_pr=$(echo $prs | jq -c .[0])
else
prs_created=false
first_pr="{}"
fi
echo "pr=$first_pr" >> "$GITHUB_OUTPUT"
echo "prs_created=$prs_created" >> "$GITHUB_OUTPUT"
fi
if [[ -z "${{ inputs.command }}" || "${{ inputs.command }}" == "release" ]]
then
echo "-- Running release-plz release --"
release-plz release\
release_output=$(release-plz release\
--git-token ${GITHUB_TOKEN}\
${CONFIG_PATH}\
${ALT_REGISTRY}\
${MANIFEST_PATH}
${MANIFEST_PATH}\
-o json)
echo "release_output: $release_output"
releases=$(echo $release_output | jq -c .releases)
echo "releases=$releases" >> "$GITHUB_OUTPUT"
releases_length=$(echo "$releases" | jq 'length')
if [ "$releases_length" != "0" ]; then
releases_created=true
else
releases_created=false
fi
echo "releases_created=$releases_created" >> "$GITHUB_OUTPUT"
fi

0 comments on commit 35a0061

Please sign in to comment.