v1.13.0 #13
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync Release with Master | |
# Triggered when a new version is released publicly | |
on: | |
release: | |
types: [ released ] | |
jobs: | |
create-sync-pull-request: | |
name: Create release sync PR | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} | |
ORG_NAME: HathorNetwork | |
PROJECT_NUMBER: 15 | |
COLUMN_FIELD: "Status" | |
COLUMN_NAME: "In Progress (Done)" | |
FROM_BRANCH: "release" | |
TO_BRANCH: "master" | |
steps: | |
- name: Checkout | |
id: checkout | |
# https://github.com/actions/checkout/releases/tag/v4.1.6 | |
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 | |
- name: Create Pull Request | |
env: | |
TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }} | |
id: create_pull | |
run: | | |
echo "Finding author of release $TAG" | |
AUTHOR=$(gh release view $TAG --json author -q '.author.login') | |
echo "release author: $AUTHOR" | |
# This just checks that the user exists, if the release could not be found the AUTHOR | |
# would be "release not found" which is a non-existant user. | |
[$(gh api -X GET search/users -f q=$AUTHOR) == "0"] && echo "Could not find author" && exit 1; | |
echo "Creating chore/sync-release-$TAG from release branch" | |
git fetch origin $TO_BRANCH:$TO_BRANCH $FROM_BRANCH:$FROM_BRANCH | |
git checkout $FROM_BRANCH | |
git checkout -b chore/sync-release-$TAG | |
git push -u origin chore/sync-release-$TAG | |
# The assignee will be the user that manually published the release | |
PR_URL=$(gh pr create \ | |
--title "chore: [${{ github.ref_name }}] Merge release into master" \ | |
--body "Automated PR to merge `release` branch into `master` based on release event." \ | |
--base "$TO_BRANCH" \ | |
--head "chore/sync-release-$TAG" \ | |
--assignee "$AUTHOR") | |
# Store values in step output | |
echo "PR_URL=$PR_URL" >> "$GITHUB_OUTPUT" | |
- name: Fetch project and column data | |
id: proj_columns | |
run: | | |
FIELD_QUERY=".fields[] | select(.name==\"$COLUMN_FIELD\") | .id" | |
FIELD_ID=$(gh project field-list $PROJECT_NUMBER --owner $ORG_NAME --format json -q "$FIELD_QUERY") | |
OPTION_QUERY=".fields[] | select(.name==\"$COLUMN_FIELD\") | .options[] | select(.name==\"$COLUMN_NAME\") | .id" | |
OPTION_ID=$(gh project field-list $PROJECT_NUMBER --owner $ORG_NAME --format json -q "$OPTION_QUERY") | |
PROJECT_QUERY=".projects[] | select(.number==$PROJECT_NUMBER) | .id" | |
PROJECT_ID=$(gh project list --owner $ORG_NAME --format json -q "$PROJECT_QUERY") | |
# Store values in step output | |
echo "PROJECT_ID=$PROJECT_ID" >> "$GITHUB_OUTPUT" | |
echo "FIELD_ID=$FIELD_ID" >> "$GITHUB_OUTPUT" | |
echo "OPTION_ID=$OPTION_ID" >> "$GITHUB_OUTPUT" | |
- name: Associate PR with project | |
env: | |
PR_URL: ${{ steps.create_pull.outputs.PR_URL }} | |
PROJECT_ID: ${{ steps.proj_columns.outputs.PROJECT_ID }} | |
FIELD_ID: ${{ steps.proj_columns.outputs.FIELD_ID }} | |
OPTION_ID: ${{ steps.proj_columns.outputs.OPTION_ID }} | |
run: | | |
ITEM_ID=$(gh project item-add $PROJECT_NUMBER \ | |
--owner $ORG_NAME \ | |
--url "$PR_URL" \ | |
--format json \ | |
-q '.id' ) | |
gh project item-edit --project-id $PROJECT_ID --id $ITEM_ID --field-id $FIELD_ID --single-select-option-id $OPTION_ID |