Skip to content

πŸ› correct syntax for output #36

πŸ› correct syntax for output

πŸ› correct syntax for output #36

name: Release workflows and actions
on:
push:
branches:
- 'main'
workflow_dispatch:
inputs:
version:
description: 'New version or major, minor, patch'
default: 'patch'
required: true
env:
GH_BOT_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
GH_BOT_NAME: "GitHub Action"
jobs:
build:
runs-on: ubuntu-latest
permissions:
actions: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Fine-grained PAT with contents:write and workflows:write
# scopes
token: ${{ secrets.CF_VOTES_RELEASE_ACTION }} # otherwise, you will failed to push refs to dest repo
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- id: build
run: |
git config user.name ${{ env.GH_BOT_NAME }}
git config user.email ${{ env.GH_BOT_EMAIL }}
npm ci
npm run build
- id: snapshot
name: Update snapshot release
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
echo "Update tag for snapshot"
git push origin :refs/tags/snapshot
git tag -f snapshot
git push --tags
echo "Update snapshot release"
gh release edit "snapshot" -t "snapshot" --prerelease
# Build the plugin
- id: tag_release
name: Create new release
if: ${{ github.event_name != 'push' }}
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
GITHUB_TOKEN: ${{ github.token }}
run: |
VERSION=$(npm version ${INPUT_VERSION} -m "πŸ”– %s" --tag-version-prefix="")
git push && git push --tags
echo ${VERSION}
BRANCH=release/${VERSION}
# Create a new branch for the release
git checkout -b ${BRANCH}
# Update references from main to the new release branch
sed -i "s|VOTE_ACTIONS_RELEASE: snapshot|VOTE_ACTIONS_RELEASE: '$VERSION'|" .github/actions/count-votes/action.yml
sed -i "s|count-votes@main|count-votes@'$VERSION'|" .github/workflows/receive-votes.yml
git add .github
git commit -m "πŸ“ Update action references for ${VERSION}"
git push --set-upstream origin ${BRANCH}
gh release create "${VERSION}" \
--title "Release ${VERSION}" \
--target ${BRANCH} \
--verify-tag
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- id: upload_artifacts
name: Upload Artifacts
env:
VERSION: ${{ steps.tag_release.outputs.version }}
GITHUB_TOKEN: ${{ github.token }}
run: |
if [ -z ${VERSION} ]; then
VERSION=snapshot
fi
echo "Updating artifacts for ${VERSION}"
# Create a tar.gz archive
tar -czf vote-record-actions-${VERSION}.tar.gz dist package.json graphql templates
gh release upload "${VERSION}" --clobber \
"vote-record-actions-${VERSION}.tar.gz#vote-record-actions-${VERSION}.tar.gz"
- id: undraft_snapshot
name: Un-draft Snapshot release
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release edit snapshot --draft=false
gh release view snapshot