fix(ci): release logic #10
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
# referred from: https://github.com/PyO3/maturin/blob/main/.github/workflows/release.yml | |
name: Release | |
on: | |
push: | |
tags: | |
- v[0-9]+.[0-9]+.[0-9]+ | |
jobs: | |
create_release : | |
if: startsWith(github.ref, 'refs/tags/') | |
name: release ${{ matrix.target }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Update CHANGELOG | |
id: changelog | |
uses: requarks/changelog-action@v1 | |
with: | |
token: ${{ github.token }} | |
tag: ${{ github.ref_name }} | |
- name: Create Release | |
uses: ncipollo/[email protected] | |
with: | |
allowUpdates: true | |
draft: false | |
makeLatest: true | |
name: ${{ github.ref_name }} | |
body: ${{ steps.changelog.outputs.changes }} | |
token: ${{ github.token }} | |
release: | |
name: release | |
needs: create_release | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
archive: tar.gz | |
- target: x86_64-pc-windows-gnu | |
os: windows-latest | |
ext: .exe | |
archive: zip | |
- target: x86_64-pc-windows-msvc | |
os: windows-latest | |
ext: .exe | |
archive: zip | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
archive: tar.gz | |
- target: x86_64-unknown-linux-musl | |
os: ubuntu-latest | |
archive: tar.gz | |
steps: | |
- name: Install dependencies | |
if: ${{ contains(matrix.target, 'musl') && startsWith(matrix.os, 'ubuntu-latest') }} | |
run: sudo apt-get update && sudo apt-get install -y musl-tools llvm clang | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Cargo build | |
run: | | |
rustup toolchain install nightly --profile minimal -t ${{ matrix.target }} | |
cargo +nightly build --release --target ${{ matrix.target }} | |
env: | |
RUSTFLAGS: -C strip=symbols | |
- name: Packaging Archive .zip | |
if: ${{ startsWith(matrix.os, 'windows-latest') }} | |
run: | | |
Get-ChildItem -Path .\README.md,.\config.example.toml,.\target\${{ matrix.target }}\release\ -Filter *.exe | | |
Compress-Archive -DestinationPath jsdelivr_proxy-${{ matrix.target }}.zip -Force | |
- name: Packaging Archive .tar.gz | |
if: ${{ !startsWith(matrix.os, 'windows-latest') }} | |
run: | | |
mkdir -p ./tmp && cp ./README.md ./config.example.toml ./target/${{ matrix.target }}/release/jsdelivr_proxy ./tmp && cd ./tmp && tar -czvf ../jsdelivr_proxy-${{ matrix.target }}.tar.gz . && cd .. && rm -rf ./tmp | |
- name: Upload asset | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ github.token }} | |
tag: ${{ github.ref }} | |
file: jsdelivr_proxy-${{ matrix.target }}.${{ matrix.archive }} | |
asset_name: jsdelivr_proxy-${{ matrix.target }}.${{ matrix.archive }} | |
docker-release: | |
name: docker release | |
needs: release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
hitokoto/jsdelivr-proxy | |
tags: | | |
type=ref,event=tag | |
type=semver,pattern=v{{version}} | |
type=semver,pattern=v{{major}}.{{minor}} | |
type=semver,pattern=v{{major}} | |
labels: | | |
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/hitokoto-osc/jsdelivr_proxy/master/README.md | |
io.artifacthub.package.logo-url=https://cdn.a632079.me/assets/images/hitokoto-logo-512x512.png | |
io.artifacthub.package.maintainers=[{"name":"a632079","email":"[email protected]"}] | |
io.artifacthub.package.license=Apache-2.0 | |
org.opencontainers.image.description=jsdelivr proxy | |
org.opencontainers.image.created=${{ github.event.release.created_at }} | |
org.opencontainers.image.name=jsdelivr-proxy | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.version={{version}} | |
org.opencontainers.image.source=https://github.com/hitokoto-osc/jsdelivr_proxy/ | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |