Skip to content

fix: add bypass argument to cache execution #97

fix: add bypass argument to cache execution

fix: add bypass argument to cache execution #97

Workflow file for this run

name: Pull request
on:
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches:
- 'main'
jobs:
ci:
name: CI
if: github.event.action != 'closed'
uses: ./.github/workflows/_build.yml
compute-version:
name: Compute version
runs-on: ubuntu-latest
if: |
contains(github.event.pull_request.labels.*.name, 'deploy') &&
(startsWith(github.head_ref, 'feature/') ||
startsWith(github.head_ref, 'fix/') ||
startsWith(github.head_ref, 'ci/'))
outputs:
canary_prefix: ${{ steps.generate_canary_version.outputs.canary_prefix }}
canary_version: ${{ steps.generate_canary_version.outputs.canary_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Generate Canary Version
id: generate_canary_version
run: |
BASE_VERSION=$(node -p "require('./package.json').version")
PR_NUMBER=${{ github.event.pull_request.number }}
COMMIT_HASH=${GITHUB_SHA::7}
CANARY_PREFIX="${BASE_VERSION}-canary.${PR_NUMBER}"
CANARY_VERSION="${CANARY_PREFIX}.${COMMIT_HASH}"
echo "CANARY_PREFIX=${CANARY_PREFIX}"
echo "CANARY_VERSION=${CANARY_VERSION}"
echo "CANARY_PREFIX=${CANARY_PREFIX}" >> $GITHUB_ENV
echo "CANARY_VERSION=${CANARY_VERSION}" >> $GITHUB_ENV
echo "canary_prefix=${CANARY_PREFIX}" >> $GITHUB_OUTPUT
echo "canary_version=${CANARY_VERSION}" >> $GITHUB_OUTPUT
publish-version:
name: Publish
runs-on: ubuntu-latest
needs: [ ci , compute-version ]
if: github.event.action != 'closed'
environment:
name: canary
url: https://www.npmjs.com/package/execution-engine/v/${{ needs.compute-version.outputs.canary_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Remove old Canary versions
id: unpublish_canary
uses: ./.github/actions/unpublish-prefix
with:
version_prefix: ${{ needs.compute-version.outputs.canary_prefix }}
confirm: 'I confirm to unpublish'
npm_token: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: npm ci
- name: Bump Version and Publish Canary
run: |
npm version ${{ needs.compute-version.outputs.canary_version }} --no-git-tag-version
npm publish --tag canary
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: prepare Cleanup Message
id: cleanup_message
shell: bash
run: |
if [[ -n "${{ steps.unpublish_canary.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}" ]]; then
# Loop through each version and add a strikethrough (~) around each
RESULT_WITH_STRIKETHROUGH=""
for version in ${{ steps.unpublish_canary.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}; do
RESULT_WITH_STRIKETHROUGH="~$version~ $RESULT_WITH_STRIKETHROUGH"
done
echo "cleanup_message=🚫 **Unpublished versions**: $RESULT_WITH_STRIKETHROUGH" >> "$GITHUB_ENV"
else
# If no unpublished versions, leave the message empty
echo "cleanup_message=🚫 **Unpublished versions**: ∅" >> "$GITHUB_ENV"
fi
- name: Comment on PR with deployed Version
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ env.cleanup_message }}
✅ **Created Version:** `${{ needs.compute-version.outputs.canary_version }}`
📦 **Published on NPM:** [View on NPM](https://www.npmjs.com/package/execution-engine/v/${{ needs.compute-version.outputs.canary_version }})
> ⚠️ **Note:** This version is temporary and will be **unpublished** on the next PR update or merge.
reactions: 'rocket'
unpublish_version:
name: Unpublish
runs-on: ubuntu-latest
needs: compute-version
if: github.event.action == 'closed'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Remove old Canary versions
id: unpublish_canary_2
uses: ./.github/actions/unpublish-prefix
with:
version_prefix: ${{ needs.compute-version.outputs.canary_prefix }}
confirm: 'I confirm to unpublish'
npm_token: ${{ secrets.NPM_TOKEN }}
- name: prepare PR comment message for unpublish
id: cleanup_message
shell: bash
run: |
if [[ -n "${{ steps.unpublish_canary_2.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}" ]]; then
# Loop through each version and add a strikethrough (~) around each
RESULT_WITH_STRIKETHROUGH=""
for version in ${{ steps.unpublish_canary_2.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}; do
RESULT_WITH_STRIKETHROUGH="~$version~ $RESULT_WITH_STRIKETHROUGH"
done
echo "cleanup_message=🚫 **Unpublished versions**: $RESULT_WITH_STRIKETHROUGH" >> "$GITHUB_ENV"
else
# If no unpublished versions, leave the message empty
echo "cleanup_message=🚫 **Unpublished versions**: ∅" >> "$GITHUB_ENV"
fi
- name: Comment on PR with deployed Version
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ env.cleanup_message }}
reactions: 'rocket'