Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 4 additions & 112 deletions .github/workflows/fast-forward.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: fast-forward and release
name: fast-forward
on:
issue_comment:
types: [created, edited]
Expand All @@ -7,17 +7,16 @@ 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:
contents: write
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
Expand All @@ -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
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
Loading