Cannot use variable values as slot names in loop #731
This file contains 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: Create a Snapshot Release | |
on: | |
issue_comment: | |
types: [created] | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
snapshot-release: | |
timeout-minutes: 3 | |
name: Create a snapshot release of a pull request | |
if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!preview') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if user has admin access (only admins can publish snapshot releases). | |
id: checkAccess | |
uses: actions-cool/check-user-permission@v2 | |
with: | |
require: admin | |
username: ${{ github.triggering_actor }} | |
# if the user does not have the required permission, we should return exit code 1 to stop the workflow | |
- name: Check user permission | |
if: steps.checkAccess.outputs.require-result == 'false' | |
run: | | |
echo "${{ github.triggering_actor }} does not have permissions on this repo." | |
echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" | |
echo "Job originally triggered by ${{ github.actor }}" | |
exit 1 | |
- name: Extract the snapshot name from comment body | |
id: getSnapshotName | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const splitComment = context.payload.comment.body.split(' '); | |
splitComment.length !== 2 && (github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'Invalid comment format. Expected: "!preview <one-word-snapshot-name>"', | |
}) || core.setFailed('Invalid comment format. Expected: "!preview <one-word-snapshot-name>"')); | |
return splitComment[1].trim(); | |
result-encoding: string | |
- name: resolve pr refs | |
id: refs | |
uses: eficode/resolve-pr-refs@main | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.refs.outputs.head_ref }} | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22 | |
- name: Setup PNPM | |
uses: pnpm/action-setup@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 16 | |
registry-url: 'https://registry.npmjs.org' | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build Packages | |
run: pnpm run build:all | |
- name: Bump Package Versions | |
id: changesets | |
run: | | |
pnpm exec changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }} > changesets.output.txt 2>&1 | |
echo ::set-output name=result::`cat changesets.output.txt` | |
env: | |
# Needs access to run the script | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish Release | |
id: publish | |
run: | | |
pnpm run release --tag next--${{ steps.getSnapshotName.outputs.result }} > publish.output.txt 2>&1 | |
echo ::set-output name=result::`cat publish.output.txt` | |
env: | |
# Needs access to publish to npm | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Pull Request Notification | |
uses: actions/github-script@v7 | |
env: | |
MESSAGE: ${{ steps.publish.outputs.result }} | |
with: | |
script: | | |
console.log(process.env.MESSAGE); | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '```\n' + process.env.MESSAGE + '\n```', | |
}) |