Skip to content

Commit

Permalink
Add the tag.yml workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ecbr0wn committed Feb 24, 2024
1 parent 7b44f40 commit cd4f5b6
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 53 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: build
name: CI Build

on:
push:
Expand All @@ -20,7 +20,7 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
Expand All @@ -29,7 +29,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

build:
name: "build"
name: build
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -38,17 +38,17 @@ jobs:
- x86_64-unknown-linux-gnu

steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: "Toolchain setup"
- name: Toolchain setup
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.TARGET }}

- name: "Build"
- name: Build
run: cargo build

- name: "Test"
- name: Test
run: cargo test
4 changes: 2 additions & 2 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# More details at https://github.com/rust-lang/rust-clippy
# and https://rust-lang.github.io/rust-clippy/

name: clippy
name: rust-clippy analyze

on:
push:
Expand All @@ -28,7 +28,7 @@ jobs:
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
Expand Down
54 changes: 27 additions & 27 deletions .github/workflows/release-example.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "tag-release-example"
name: tag-release-example

on:
workflow_dispatch:
Expand All @@ -11,26 +11,26 @@ on:
jobs:
# Check the rust formatting
format:
name: "format"
name: rust-format
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: "Rust Toolchain setup"
- name: Rust Toolchain setup
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: "Format Check"
- name: Format Check
uses: mbrobbel/rustfmt-check@master
with:
token: ${{ secrets.GITHUB_TOKEN }}

# Build the Linux release artifacts
tag-release-example-linux:
name: "tag-release-example-linux"
runs-on: "ubuntu-latest"
tag-release-example:
name: tag-release example
runs-on: ubuntu-latest
needs: format
strategy:
matrix:
Expand All @@ -39,10 +39,10 @@ jobs:
- x86_64-unknown-linux-gnu

steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: "Toolchain setup"
- name: Toolchain setup
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.RUST }}
Expand All @@ -57,16 +57,16 @@ jobs:
- name: Build
run: cross build --release --target=${{ matrix.TARGET }}

- name: "Package Release"
- name: Package Release
run: tar cvzf snapcraft-rust-example-${{ matrix.TARGET }}.tar.gz --directory=target/${{ matrix.TARGET }}/release snapcraft-rust-example

- name: "Generate SHA checksum"
- name: Generate SHA checksum
run: shasum -a 256 -U snapcraft-rust-example-${{ matrix.TARGET }}.tar.gz > snapcraft-rust-example-${{ matrix.TARGET }}.sha

- name: "Generate MD5 checksum"
- name: Generate MD5 checksum
run: md5sum --tag snapcraft-rust-example-${{ matrix.TARGET }}.tar.gz > snapcraft-rust-example-${{ matrix.TARGET }}.md5

- name: "Upload the artifact with the workflow run"
- name: Upload the artifact with the workflow run
uses: actions/upload-artifact@v3
with:
name: snapcraft-rust-example-${{ matrix.TARGET }}-${{ github.event.inputs.example_version }}
Expand All @@ -75,20 +75,20 @@ jobs:

# Package the artifacts as a release package
tag-release-example-package:
name: "tag-release-example-linux-package"
runs-on: "ubuntu-latest"
name: Package the tag-release example
runs-on: ubuntu-latest
permissions: write-all
needs: [tag-release-example-linux]
needs: [tag-release-example]

steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: "Download all release artifacts from the workflow"
- name: Download all release artifacts from the workflow
uses: actions/download-artifact@v3

- name: "Create Example Release"
uses: "marvinpinto/action-automatic-releases@latest"
- name: Create Example Release
uses: marvinpinto/action-automatic-releases@latest
with:
automatic_release_tag: "${{ github.event.inputs.example_version }}"
title: "Release ${{ github.event.inputs.example_version }}"
Expand All @@ -100,11 +100,11 @@ jobs:
# Kick off the workflow in the snap repo (a1ecbr0wn/snapcraft) that will generate the snapcraft yaml file
generate-snap:
name: "Initiate the generation of the snapcraft yaml file"
name: Initiate the generation of the snapcraft yaml file
runs-on: ubuntu-latest
needs: [tag-release-example-linux]
needs: [tag-release-example]
steps:
- name: "Repository Dispatch"
- name: Repository Dispatch
uses: benc-uk/workflow-dispatch@v1
with:
token: ${{ secrets.PAT }}
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/release-lib.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "tag-release-build"
name: Release Binaries on Tag

on:
push:
Expand All @@ -9,19 +9,19 @@ on:

jobs:
tag-release-lib-build:
name: "tag-release-lib-build"
runs-on: "ubuntu-latest"
name: Build tag as a release
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable]
TARGET:
- x86_64-unknown-linux-gnu

steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: "Toolchain setup"
- name: Toolchain setup
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
Expand All @@ -33,18 +33,18 @@ jobs:
- name: Test
run: cargo test --release

- name: "Publish to crates.io"
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: "${{ secrets.CRATES_TOKEN }}"
run: cargo publish -p snapcraft

# Kick off the workflow for the creation of the snapcraft example
tag-release-example-init:
name: "Initiate release of the snapcraft example application"
name: Initiate release of the snapcraft example application
runs-on: ubuntu-latest
needs: [tag-release-lib-build]
steps:
- name: "Repository Dispatch"
- name: Repository Dispatch
uses: benc-uk/workflow-dispatch@v1
with:
token: ${{ secrets.PAT }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/snap.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "generate-snap"
name: Generate Snap

on:
workflow_dispatch:
Expand All @@ -10,11 +10,11 @@ on:

jobs:
generate-formula:
name: "Generate a snap file"
name: Generate a snap file
runs-on: ubuntu-latest
steps:

- name: "Set Version"
- name: Set Version
run: |
input_version="${{ github.event.inputs.snap_version }}"
if [ "${#input_version}" -eq "0" ]; then
Expand All @@ -25,18 +25,18 @@ jobs:
- run: echo 'Release ${{ env.snap_version }}'

- name: "Checkout"
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: "Create the snap from the template"
- name: Create the snap from the template
run: |
cp template/snapcraft.yaml snapcraft.yaml
cat snapcraft.yaml
sed -i 's/:snap_version/${{ env.snap_version }}/' snapcraft.yaml
echo " --- "
cat snapcraft.yaml
- name: "Create Pull Request"
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
name: Tag a release

on:
workflow_dispatch:
inputs:

version:
description: 'Tag to apply, in the form "v0.0.0"'
required: true

jobs:
tag-release:
name: Given the tag input value, check the value, update the version number of the application, commit, tag, push tag
runs-on: ubuntu-latest

steps:
- name: Check the version number from input
run: |
echo "Validating that tag is a tag is in the correct format v0.0.1"
input_version="${{ github.event.inputs.version }}"
if grep -P '^v[0-9]+\.[0-9]+\.[0-9]+' <<< "${input_version}"; then
echo "tag=${input_version}" >> $GITHUB_ENV
echo "cargo_version=version = \"${input_version:1}\"" >> $GITHUB_ENV
elif grep -P '^[0-9]+\.[0-9]+\.[0-9]+' <<< "${input_version}"; then
echo "tag=v${input_version}" >> $GITHUB_ENV
echo "cargo_version=version = \"${input_version}\"" >> $GITHUB_ENV
else
false
fi
- name: Setup GPG
run: |
echo "${{ secrets.SIGNINGKEY }}" | gpg --import
- name: Checkout code
uses: actions/checkout@v4

- name: Setup git config
run: |
# setup the username and email.
git config user.name "Tag Bot"
git config user.email "github@noser.net"
# setup gpg configuration
git config commit.gpgsign true
git config user.signingkey ${{ secrets.SIGNINGKEYHASH }}
- name: Replace the version number in the Cargo.toml files
run: |
sed -i 's/^version = .*/${{ env.cargo_version }}/g' Cargo.toml
- name: Add, push, tag, push
run: |
git add .
git commit -S -m "Release ${{ env.tag }}"
git push -f
git tag ${{ env.tag }} -s -m "Release ${{ env.tag }}"
git push origin ${{ env.tag }} -f
- name: Release Tag Repository Dispatch
uses: benc-uk/workflow-dispatch@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{env.GITHUB_REPOSITORY}}
ref: refs/tags/${{ env.tag }}
workflow: release.yml

0 comments on commit cd4f5b6

Please sign in to comment.