diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26c67c2..f5af7ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test on: push: branches: - - 'main' + - "main" paths-ignore: - "**.md" pull_request: @@ -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 diff --git a/action.yml b/action.yml index 3eba247..9a9769a 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -43,6 +61,7 @@ runs: - name: Configure git user from GitHub token uses: MarcoIeni/git-config@v0.1 - name: Run release-plz + id: release-plz shell: bash run: | if [[ -n "${{ inputs.config }}" ]] @@ -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