Skip to content

Commit

Permalink
feat: simplify release process
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkuridza committed May 3, 2024
1 parent 130c425 commit dcd38f9
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 99 deletions.
81 changes: 0 additions & 81 deletions .github/workflows/artifacts.yaml

This file was deleted.

145 changes: 138 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,150 @@ on:
- cron: "0 0 * * *"
workflow_dispatch:

# Allow only one release workflow at a time to avoid using shared resources (tags, ...).
# See https://docs.github.com/en/actions/using-jobs/using-concurrency for details.
concurrency:
group: ${{ github.workflow }}

permissions:
contents: write

jobs:
get-next-version:
uses: semantic-release-action/next-release-version/.github/workflows/next-release-version.yml@v4

build:
name: Build for ${{ matrix.target }}
if: needs.get-next-version.outputs.new-release-published == 'true'
runs-on: ${{ matrix.build.os }}
needs:
- get-next-version

strategy:
matrix:
build:
- os: macos-latest
target: x86_64-apple-darwin
cross: false
- os: macos-latest
target: aarch64-apple-darwin
cross: true
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
cross: false

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
id: rust-toolchain
with:
toolchain: stable
target: ${{ matrix.build.target }}

- name: Cache cargo
uses: actions/cache@v4
id: cache-cargo
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}

- name: Install semantic-release-cargo
uses: taiki-e/install-action@v2
with:
tool: semantic-release-cargo@2

- name: Prepare semantic-release for Rust
run: semantic-release-cargo prepare ${{ needs.get-next-version.outputs.new-release-version }}

- name: Install cross
uses: taiki-e/install-action@v2
with:
tool: cross

- name: Configure cross
if: matrix.build.cross
run: echo "CARGO=cross" >> "$GITHUB_ENV"

- name: Compile release binary
run: cargo build --release --target ${{ matrix.build.target }} --verbose

- name: Create release archive
run: |
mkdir dist
cp target/${{ matrix.build.target }}/release/gitlab-ci-ls dist/gitlab-ci-ls-${{ matrix.build.target }}
- name: Create binary checksum
run: shasum --algorithm 256 --binary gitlab-ci-ls-${{ matrix.build.target }} | tee gitlab-ci-ls-${{ matrix.build.target }}-checksums.txt
working-directory: ./dist

- name: Upload release artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.build.target }}
path: |
dist/gitlab-ci-ls-${{ matrix.build.target }}
dist/gitlab-ci-ls-${{ matrix.build.target }}-checksums.txt
if-no-files-found: error
retention-days: 1

release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
name: Release
if: needs.get-next-version.outputs.new-release-published == 'true'
needs:
- build
- get-next-version

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
id: rust-toolchain
with:
persist-credentials: false
toolchain: stable

- name: Cache cargo
uses: actions/cache@v4
id: cache-cargo
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}

- name: Download release artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: ls artifacts
run: ls -R ./artifacts

- name: Prepare GitHub Release artifacts
run: |
mkdir ./dist
mv ./artifacts/x86_64-apple-darwin ./dist
mv ./artifacts/aarch64-apple-darwin ./dist
mv ./artifacts/x86_64-unknown-linux-gnu ./dist
- name: Combine checksums
run: cat dist/**/gitlab-ci-ls-*-checksums.txt | tee dist/checksums.txt

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
with:
Expand Down
64 changes: 64 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"branches": [
"main"
],
"debug": true,
"ci": true,
"dryRun": false,
"tagFormat": "${version}",
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "chore",
"release": "patch"
},
{
"type": "deps",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
}
]
}
],
"@semantic-release/release-notes-generator",
[
"@semantic-release/github",
{
"assets": [
{
"path": "dist/x86_64-apple-darwin/gitlab-ci-ls-x86_64-apple-darwin",
"label": "x86_64-apple-darwin"
},
{
"path": "dist/aarch64-apple-darwin/gitlab-ci-ls-aarch64-apple-darwin",
"label": "aarch64-apple-darwin"
},
{
"path": "dist/x86_64-unknown-linux-gnu/gitlab-ci-ls-x86_64-unknown-linux-gnu",
"label": "x86_64-unknown-linux-gnu"
},
{
"path": "dist/checksums.txt",
"label": "checksums.txt"
}
]
}
],
[
"@semantic-release/git",
{
"assets": [
"Cargo.toml",
"Cargo.lock"
]
}
],
"semantic-release-cargo"
]
}
11 changes: 0 additions & 11 deletions .releaserc.yaml

This file was deleted.

0 comments on commit dcd38f9

Please sign in to comment.