Skip to content

Commit

Permalink
build: update workflow to have write permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed May 20, 2024
1 parent f76aa57 commit 91b881f
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 134 deletions.
4 changes: 4 additions & 0 deletions .changeset/sixty-swans-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

build: update CI step for creating changesets + reporting coverage
98 changes: 0 additions & 98 deletions .github/workflows/pr-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,101 +53,3 @@ jobs:
echo "PR title is too long (greater than 72 characters)"
exit 1
fi
validate-changeset:
name: Validate PR Changeset
if: startsWith(github.head_ref, 'changeset-release') != true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: CI Setup
uses: ./.github/actions/ci-setup

- name: Validate Changeset
run: pnpm changeset status --since=origin/${{ github.base_ref }}

- name: Validate Changeset Content
run: |
CHANGESET_FILE=$(git diff --diff-filter=A --name-only origin/${{ github.base_ref }} .changeset/*.md)
if [ -z "$CHANGESET_FILE" ]; then
# A PR doesn't have to have a changeset when packages aren't affected
# e.g. when a script is added in the scripts folder
exit 0
fi
echo "CHANGESET_FILE=$(echo "$CHANGESET_FILE")" >> $GITHUB_ENV
AFFECTED_PACKAGES=$(sed -n '/---/,/---/p' "$CHANGESET_FILE" | sed '/---/d')
if [ -z "$AFFECTED_PACKAGES" ]; then
# The changelog logic ignores changesets that don't affect any packages so we can ignore them here as well,
# because this changeset linting logic is only for changesets who's PRs will be referenced in the changelog.
# The relevant changelog logic is here:
# https://github.com/FuelLabs/fuels-ts/blob/155b6f2fe28e988b277dac231af6d6a0cff1df0c/scripts/changeset/get-full-changelog.mts#L77
exit 0
fi
# TODO: Remove once v1.0.0 is released.
# Minor changes are treated as breaking until v1.0.0 is released.
if echo "$AFFECTED_PACKAGES" | grep -q 'minor'; then
if ! echo "$PR_TITLE" | grep -q '!'; then
echo "Changeset has `minor` changes. Please mark the PR as breaking by adding an exclamation mark to its title (e.g. fix!: xxx) or use a `patch` instead."
exit 1
fi
fi
CHANGESET_DESCRIPTION=$(sed 's/^\s*\|\s*$//g' "$CHANGESET_FILE" | tail -n1)
if [ "$CHANGESET_DESCRIPTION" != "$PR_TITLE" ]; then
echo "Changeset content does not match PR title. Please update the changeset to match the PR title."
echo "Changeset file: $CHANGESET_FILE"
echo "Changeset content:"
cat "$CHANGESET_FILE"
exit 1
fi
env:
PR_TITLE: ${{ github.event.pull_request.title }}

- name: Validate added changeset will be deleted
if: ${{ env.CHANGESET_FILE != '' }}
run: |
pnpm changeset version
if git status --porcelain .changeset | grep -q "D $CHANGESET_FILE"; then
git reset --hard
exit 0
fi
# Throw if changeset not in deleted changesets
echo "Changeset file $CHANGESET_FILE will not get deleted in the changesets PR. Check its affected packages."
exit 1
env:
CHANGESET_FILE: ${{ env.CHANGESET_FILE }}

- name: Validate that there are only patch changes
if: startsWith(github.base_ref, 'release/')
run: |
CHANGES=$(sed -n '/---/,/---/p' .changeset/*.md)
echo $CHANGES | grep -E 'patch' --silent && echo "Patch changes found." || (echo "No patch changes found." && exit 1)
echo $CHANGES | grep -E 'minor|major' --silent && echo "Old releases can only be patched; no minor and major versions allowed." && exit 1 || echo "No minor nor major changes."
- name: Validate that there was no release for the next patch version
if: startsWith(github.base_ref, 'release/')
run: |
pnpm changeset version
VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' packages/fuels/package.json)
git reset --hard
STATUS_CODE=$(curl -s -w '%{http_code}\n' "https://www.npmjs.com/package/fuels/v/$VERSION" | tail -n1)
if [[ $STATUS_CODE != 404 ]]; then
echo "Release for version $VERSION already exists or curl received an unexpected result (result is $STATUS_CODE). Exiting."
exit 1
else
exit 0
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145 changes: 145 additions & 0 deletions .github/workflows/pr-validate-changesets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Validate Changesets

on:
pull_request:
push:
branches:
- master

permissions:
pull-requests: write
repository-projects: write

jobs:
create-changeset:
name: Create Changeset
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.ref }}

- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
version: 9.0.5
run_install: true

- name: Install jq
run: sudo apt-get install -y jq

- name: Run dependabot changeset script
run: pnpm changeset:dependabot
env:
PR_TITLE: ${{ github.event.pull_request.title }}

- name: Commit Changeset
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git commit -m "build: update dependency changeset [skip ci]"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

validate-changeset:
name: Validate PR Changeset
if: startsWith(github.head_ref, 'changeset-release') != true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: CI Setup
uses: ./.github/actions/ci-setup

- name: Validate Changeset
run: pnpm changeset status --since=origin/${{ github.base_ref }}

- name: Validate Changeset Content
run: |
CHANGESET_FILE=$(git diff --diff-filter=A --name-only origin/${{ github.base_ref }} .changeset/*.md)
if [ -z "$CHANGESET_FILE" ]; then
# A PR doesn't have to have a changeset when packages aren't affected
# e.g. when a script is added in the scripts folder
exit 0
fi
echo "CHANGESET_FILE=$(echo "$CHANGESET_FILE")" >> $GITHUB_ENV
AFFECTED_PACKAGES=$(sed -n '/---/,/---/p' "$CHANGESET_FILE" | sed '/---/d')
if [ -z "$AFFECTED_PACKAGES" ]; then
# The changelog logic ignores changesets that don't affect any packages so we can ignore them here as well,
# because this changeset linting logic is only for changesets who's PRs will be referenced in the changelog.
# The relevant changelog logic is here:
# https://github.com/FuelLabs/fuels-ts/blob/155b6f2fe28e988b277dac231af6d6a0cff1df0c/scripts/changeset/get-full-changelog.mts#L77
exit 0
fi
# TODO: Remove once v1.0.0 is released.
# Minor changes are treated as breaking until v1.0.0 is released.
if echo "$AFFECTED_PACKAGES" | grep -q 'minor'; then
if ! echo "$PR_TITLE" | grep -q '!'; then
echo "Changeset has `minor` changes. Please mark the PR as breaking by adding an exclamation mark to its title (e.g. fix!: xxx) or use a `patch` instead."
exit 1
fi
fi
CHANGESET_DESCRIPTION=$(sed 's/^\s*\|\s*$//g' "$CHANGESET_FILE" | tail -n1)
if [ "$CHANGESET_DESCRIPTION" != "$PR_TITLE" ]; then
echo "Changeset content does not match PR title. Please update the changeset to match the PR title."
echo "Changeset file: $CHANGESET_FILE"
echo "Changeset content:"
cat "$CHANGESET_FILE"
exit 1
fi
env:
PR_TITLE: ${{ github.event.pull_request.title }}

- name: Validate added changeset will be deleted
if: ${{ env.CHANGESET_FILE != '' }}
run: |
pnpm changeset version
if git status --porcelain .changeset | grep -q "D $CHANGESET_FILE"; then
git reset --hard
exit 0
fi
# Throw if changeset not in deleted changesets
echo "Changeset file $CHANGESET_FILE will not get deleted in the changesets PR. Check its affected packages."
exit 1
env:
CHANGESET_FILE: ${{ env.CHANGESET_FILE }}

- name: Validate that there are only patch changes
if: startsWith(github.base_ref, 'release/')
run: |
CHANGES=$(sed -n '/---/,/---/p' .changeset/*.md)
echo $CHANGES | grep -E 'patch' --silent && echo "Patch changes found." || (echo "No patch changes found." && exit 1)
echo $CHANGES | grep -E 'minor|major' --silent && echo "Old releases can only be patched; no minor and major versions allowed." && exit 1 || echo "No minor nor major changes."
- name: Validate that there was no release for the next patch version
if: startsWith(github.base_ref, 'release/')
run: |
pnpm changeset version
VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' packages/fuels/package.json)
git reset --hard
STATUS_CODE=$(curl -s -w '%{http_code}\n' "https://www.npmjs.com/package/fuels/v/$VERSION" | tail -n1)
if [[ $STATUS_CODE != 404 ]]; then
echo "Release for version $VERSION already exists or curl received an unexpected result (result is $STATUS_CODE). Exiting."
exit 1
else
exit 0
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 0 additions & 36 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,39 +128,3 @@ jobs:
comment_tag: diff
mode: recreate
create_if_not_exists: true

create-changeset:
needs: [test]
name: Create Changeset
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.ref }}

- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
version: 9.0.5
run_install: true

- name: Install jq
run: sudo apt-get install -y jq

- name: Run dependabot changeset script
run: pnpm changeset:dependabot
env:
PR_TITLE: ${{ github.event.pull_request.title }}

- name: Commit Changeset
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git commit -m "build: update dependency changeset [skip ci]"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}

0 comments on commit 91b881f

Please sign in to comment.