diff --git a/.github/workflows/fast-forward.yml b/.github/workflows/fast-forward.yml index af6a024a..46122234 100644 --- a/.github/workflows/fast-forward.yml +++ b/.github/workflows/fast-forward.yml @@ -1,4 +1,4 @@ -name: fast-forward and release +name: fast-forward on: issue_comment: types: [created, edited] @@ -7,6 +7,9 @@ jobs: # Only run if the comment contains the /fast-forward command. if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/fast-forward') }} runs-on: ubuntu-latest + concurrency: + group: fast-forward-${{ github.event.issue.number }} + cancel-in-progress: true # https://docs.github.com/ko/actions/writing-workflows/workflow-syntax-for-github-actions#permissions permissions: @@ -14,10 +17,6 @@ jobs: pull-requests: write issues: write - outputs: - should_run: ${{ steps.check_branch.outputs.should_run }} - head_sha: ${{ steps.check_branch.outputs.head_sha }} - steps: - name: Check comment id: check_comment @@ -40,110 +39,3 @@ jobs: # never post a comment. (In all cases the information is # still available in the step's summary.) comment: always - - - name: Check target branch - if: ${{ steps.check_comment.outputs.MATCH == 'true' }} - id: check_branch - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # From https://github.com/sequoia-pgp/fast-forward/blob/main/src/fast-forward.sh - PR_URL="${{ github.event.issue.pull_request.url }}" - if test "x$PR_URL" = x - then - echo "Unable to find pull request's context." - exit 1 - fi - - GITHUB_PR=$(mktemp) - function get_pr_info { - # https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request - curl --silent --show-error --location \ - -X GET \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "$PR_URL" >$GITHUB_PR - } - - function check_pr_merged { - local merged_status="false" - local attempt=1 - local max_attempts=30 - local sleep_duration=1 - - while [ "$merged_status" != "true" ] && [ $attempt -le $max_attempts ]; do - get_pr_info - merged_status=$(jq -r ".merged" <$GITHUB_PR) - - if [ "$merged_status" = "true" ]; then - break - else - sleep $sleep_duration - ((attempt++)) - fi - done - - if [ $attempt -gt $max_attempts ]; then - echo "The maximum number of attempts has been reached. The pull request was not merged." - exit 1 - fi - } - - get_pr_info - BASE_REF=$(jq -r ".base.ref" <$GITHUB_PR) - if [ "$BASE_REF" = "main" ]; then - echo "should_run=true" >> $GITHUB_OUTPUT - echo "head_sha=$(jq -r ".head.sha" <$GITHUB_PR)" >> $GITHUB_OUTPUT - check_pr_merged - else - echo "should_run=false" >> $GITHUB_OUTPUT - fi - - release: - name: Release - needs: fast-forward - if: needs.fast-forward.outputs.should_run == 'true' - - runs-on: ubuntu-latest - - permissions: - contents: write - issues: write - pull-requests: write - packages: write - statuses: write - - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ needs.fast-forward.outputs.head_sha }} - - - name: Setup - uses: ./.github/actions/node-setup - - - name: Create Release Pull Request or Publish to npm - id: changesets - uses: changesets/action@v1 - with: - commit: "Chore: Version Packages" - publish: yarn run publish - version: yarn run changeset:version - setupGitUser: true - createGithubReleases: true - env: - PACKAGE_PUBLISH: "true" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Show log on failure - if: failure() - run: | - cd /home/runner/.npm/_logs/ || exit - for file in *; do - echo "=== File: $file ===" - cat "$file" - echo -e "\n\n" - done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..e1e801e7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: release +on: + push: + branches: + - main + +jobs: + release: + name: Release + runs-on: ubuntu-latest + + permissions: + contents: write + issues: write + pull-requests: write + packages: write + statuses: write + + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup + uses: ./.github/actions/node-setup + + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/action@v1 + with: + commit: "Chore: Version Packages" + publish: yarn run publish + version: yarn run changeset:version + setupGitUser: true + createGithubReleases: true + env: + PACKAGE_PUBLISH: "true" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Show log on failure + if: failure() + run: | + cd /home/runner/.npm/_logs/ || exit + for file in *; do + echo "=== File: $file ===" + cat "$file" + echo -e "\n\n" + done