fix(ci): use gh env to skip steps #54
Workflow file for this run
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: Release new version | |
on: | |
push: | |
tags: | |
- v* | |
jobs: | |
change-log-and-release: | |
name: Prepare release & generate changelog | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ssh-key: ${{ secrets.RELEASE_DEPLOY_KEY }} | |
- name: Extract version from Github Ref | |
id: extract_version | |
run: | | |
echo VERSION=$(echo ${{ github.ref }} | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+") >> $GITHUB_ENV | |
- name: Bump Version on Cargo.toml | |
run: | | |
VERSION=$(echo ${{ env.VERSION }} | grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+") | |
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml | |
- name: Git Cliff | |
id: generate_changelog | |
uses: orhun/git-cliff-action@v3 | |
with: | |
config: cliff.toml | |
args: -l --prepend CHANGELOG.md --strip header | |
env: | |
GITHUB_REPO: ${{ github.repository }} | |
- name: Print Changelog | |
run: cat ${{ steps.generate_changelog.outputs.changelog }} && echo "##" && cat CHANGELOG.md | |
- name: Commit Version and CHANGELOG.md | |
run: | | |
git checkout origin/main | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
set +e | |
git add Cargo.toml CHANGELOG.md | |
cargo check | |
git add Cargo.lock | |
git commit -m "chore(release): prepare for ${{ env.VERSION }}" | |
git push origin HEAD:main | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: ${{ env.VERSION }} | |
body_path: ${{ steps.generate_changelog.outputs.changelog }} | |
draft: false | |
prerelease: false | |
build: | |
name: Build and upload artifacts | |
runs-on: ubuntu-latest | |
needs: change-log-and-release | |
container: | |
image: antonengelhardt/rust-docker-tools | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up cargo cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Build | |
run: | | |
cargo build --target wasm32-wasi --release | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: wasm_oidc_plugin.wasm | |
path: target/wasm32-wasi/release/wasm_oidc_plugin.wasm | |
docker-image: | |
name: Build and push Docker image | |
runs-on: ubuntu-latest | |
needs: change-log-and-release | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Extract version from Github Ref | |
id: extract_version | |
run: | | |
echo VERSION=$(echo ${{ github.ref }} | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+") >> $GITHUB_ENV | |
- name: Push to Docker Hub | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: antonengelhardt/wasm-oidc-plugin:${{ env.VERSION }} | |
ghcr-image: | |
name: Build and push GHCR image | |
runs-on: ubuntu-latest | |
needs: change-log-and-release | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract version from Github Ref | |
id: extract_version | |
run: | | |
echo VERSION=$(echo ${{ github.ref }} | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+") >> $GITHUB_ENV | |
- name: Push to GHCR | |
run: | | |
docker build -t ghcr.io/antonengelhardt/wasm-oidc-plugin:${{ env.VERSION }} . | |
docker push ghcr.io/antonengelhardt/wasm-oidc-plugin:${{ env.VERSION }} |