From d0c02f444323261a46d775c0d63f73376b31e946 Mon Sep 17 00:00:00 2001 From: tmknight Date: Sun, 14 Jan 2024 16:58:46 -0500 Subject: [PATCH 1/2] Build and release workflows --- .../{cargo-build.yml => cargo-check.yml} | 11 +- .github/workflows/git-release.yml | 104 ++++++++++++++++++ .github/workflows/git-tag.yml | 40 +++++++ 3 files changed, 149 insertions(+), 6 deletions(-) rename .github/workflows/{cargo-build.yml => cargo-check.yml} (74%) create mode 100644 .github/workflows/git-release.yml create mode 100644 .github/workflows/git-tag.yml diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-check.yml similarity index 74% rename from .github/workflows/cargo-build.yml rename to .github/workflows/cargo-check.yml index b60615b..391431d 100644 --- a/.github/workflows/cargo-build.yml +++ b/.github/workflows/cargo-check.yml @@ -1,4 +1,4 @@ -name: Cargo build & test +name: "Cargo Check" on: push: @@ -20,12 +20,11 @@ env: jobs: build: - runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - name: Check + run: cargo check + - name: Clippy + run: cargo clippy -- -D warnings diff --git a/.github/workflows/git-release.yml b/.github/workflows/git-release.yml new file mode 100644 index 0000000..c7027e1 --- /dev/null +++ b/.github/workflows/git-release.yml @@ -0,0 +1,104 @@ +name: "Git Release" + +permissions: + contents: "write" + +on: + workflow_run: + workflows: ["Git Tag"] + types: + - "completed" + +jobs: + get-tag: + name: "Get Tag From Package Version" + runs-on: "ubuntu-latest" + outputs: + pkg-version: ${{ steps.pkg-version.outputs.PKG_VERSION }} + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: "Get tag" + id: "pkg-version" + shell: "bash" + run: | + echo PKG_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' Cargo.toml) >> $GITHUB_OUTPUT + + create-release: + name: "Create release" + if: ${{ github.event.workflow_run.conclusion == 'success' }} + needs: "get-tag" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - name: "Create release" + uses: "taiki-e/create-gh-release-action@v1" + with: + # (optional) Path to changelog. + # changelog: CHANGELOG.md + branch: "main" + ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }} + token: ${{ secrets.GITHUB_TOKEN }} + + upload-assets: + name: "Upload assets to Github releases" + if: ${{ github.event.workflow_run.conclusion == 'success' }} + needs: + - "get-tag" + - "create-release" + strategy: + matrix: + include: + - target: "x86_64-unknown-linux-gnu" + os: "ubuntu-latest" + - target: "x86_64-unknown-linux-musl" + os: "ubuntu-latest" + runs-on: ${{ matrix.os }} + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + + - name: "Upload Binaries" + uses: "taiki-e/upload-rust-binary-action@v1" + with: + bin: "docker-autoheal" + target: ${{ matrix.target }} + archive: $bin-${{ matrix.target }} + ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }} + token: ${{ secrets.GITHUB_TOKEN }} + +# push-to-registry: +# name: "Push Docker image to Docker Hub" +# if: ${{ github.event.workflow_run.conclusion == 'success' }} +# needs: +# - "get-tag" +# - "upload-assets" +# runs-on: "ubuntu-latest" +# steps: +# - name: "Check out the repo" +# uses: actions/checkout@v3 + +# - name: "Log in to Docker Hub" +# uses: "docker/login-action@v2" +# with: +# username: ${{ secrets.DOCKER_USERNAME }} +# password: ${{ secrets.DOCKER_PASSWORD }} + +# - name: "Extract metadata (tags, labels) for Docker" +# id: "meta" +# uses: "docker/metadata-action@v4" +# with: +# images: "bwks/shazam" + +# - name: "Build and push Docker image" +# uses: "docker/build-push-action@v3" +# with: +# context: . +# push: true +# tags: bwks/shazam:latest,bwks/shazam:v${{ needs.get-tag.outputs.pkg-version }} +# labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/git-tag.yml b/.github/workflows/git-tag.yml new file mode 100644 index 0000000..1d9e122 --- /dev/null +++ b/.github/workflows/git-tag.yml @@ -0,0 +1,40 @@ +name: "Git Tag" + +on: + # push: + # paths-ignore: + # - '.github/**' + # - 'examples/**' + # - 'docker/**' + # - 'test/**' + # - '*.md' + # - '.*' + # - '*.lock' + # - '.LICENSE' + # branches: [ "main", "develop" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + create-tag: + name: "Create tag" + runs-on: "ubuntu-latest" + steps: + - name: "Check out the repo" + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: "Get tag" + id: "get-tag" + shell: "bash" + run: | + echo PKG_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' Cargo.toml) >> $GITHUB_OUTPUT + + - name: "Set Tag" + shell: "bash" + run: | + git tag v${{ steps.get-tag.outputs.PKG_VERSION }} && git push --tags From 18421c82e446532b4de03951fc4fdd95206a5ee5 Mon Sep 17 00:00:00 2001 From: tmknight Date: Sun, 14 Jan 2024 17:01:37 -0500 Subject: [PATCH 2/2] Add workflow_dispatch --- .github/workflows/cargo-check.yml | 1 + .github/workflows/git-tag.yml | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cargo-check.yml b/.github/workflows/cargo-check.yml index 391431d..04cc2a6 100644 --- a/.github/workflows/cargo-check.yml +++ b/.github/workflows/cargo-check.yml @@ -1,6 +1,7 @@ name: "Cargo Check" on: + workflow_dispatch: push: paths-ignore: - '.github/**' diff --git a/.github/workflows/git-tag.yml b/.github/workflows/git-tag.yml index 1d9e122..830aebf 100644 --- a/.github/workflows/git-tag.yml +++ b/.github/workflows/git-tag.yml @@ -1,6 +1,7 @@ name: "Git Tag" on: + workflow_dispatch: # push: # paths-ignore: # - '.github/**' @@ -12,8 +13,8 @@ on: # - '*.lock' # - '.LICENSE' # branches: [ "main", "develop" ] - pull_request: - branches: [ "main" ] + pull_request: + branches: [ "main" ] env: CARGO_TERM_COLOR: always