Merge pull request #797 from cdklabs/github-actions/release #257
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
# .github/workflows/release.yml | |
name: Release from release branch | |
on: | |
workflow_dispatch: {} | |
push: | |
branches: | |
- release | |
env: | |
RELEASE_BRANCH: release | |
MERGEBACK_BRANCH: github-actions/mergeback | |
jobs: | |
create_mergeback: | |
name: Create the merge-back PR | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.RELEASE_BRANCH }} | |
token: ${{ secrets.PROJEN_GITHUB_TOKEN }} | |
fetch-depth: 0 | |
- name: Prepare git identity | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "cdklabs-automation" | |
- name: Create merge-back commit | |
# We would use a pull request, but the merge require forces a squash merge | |
# and we want a history-preserving merge here. So we do a bypassing commit to main instead. | |
run: | | |
git fetch origin main | |
git checkout main | |
git merge origin/${{ env.RELEASE_BRANCH }} -m "chore: merge-back" | |
git push origin main | |
release_to_npm: | |
name: Release to NPM | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.RELEASE_BRANCH }} | |
token: ${{ secrets.PROJEN_GITHUB_TOKEN }} | |
- name: Setup Node.js | |
uses: actions/setup-node@main | |
with: | |
node-version: lts/* | |
- name: 🦀 Install Rust | |
uses: actions-rust-lang/setup-rust-toolchain@v1 | |
- name: ⚡ Cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
${{ runner.os }}-cargo | |
- name: Install wasm-pack | |
uses: baptiste0928/cargo-install@v3 | |
with: | |
crate: wasm-pack | |
- name: Prepare Release | |
run: |- | |
wasm-pack build --all-features --target=nodejs --out-name=index | |
- name: Determine build version | |
id: build | |
run: |- | |
echo "name=$(node -p 'require("./pkg/package.json").name')" >> $GITHUB_OUTPUT | |
echo "version=$(node -p 'require("./pkg/package.json").version')" >> $GITHUB_OUTPUT | |
- name: Check if ${{ steps.build.outputs.name }}@${{ steps.build.outputs.version }} is already published | |
id: published | |
run: |- | |
npm_view=$(npm view ${{ steps.build.outputs.name }}@${{ steps.build.outputs.version }} 2> /dev/null || true) | |
if [ -z "${npm_view}" ]; then | |
echo "published=false" >> $GITHUB_OUTPUT | |
else | |
echo "published=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Release | |
if: steps.published.outputs.published == 'false' | |
run: |- | |
npm set "//registry.npmjs.org/:_authToken" ${{ secrets.NPM_TOKEN }} | |
wasm-pack publish --tag latest |