Release #7
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" | |
permissions: | |
contents: "write" | |
packages: write | |
id-token: write | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
on: | |
push: | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
workflow_dispatch: | |
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) }' ocpp/Cargo.toml) >> $GITHUB_OUTPUT | |
create-release: | |
name: "Create release" | |
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" | |
needs: | |
- "get-tag" | |
- "create-release" | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Check out the repo" | |
uses: actions/checkout@v3 | |
- run: sudo apt-get install --yes --no-install-recommends musl-tools | |
- name: "Setup Protoc" | |
uses: arduino/setup-protoc@v3 | |
- uses: dtolnay/rust-toolchain@v1 | |
with: | |
toolchain: stable | |
target: x86_64-unknown-linux-musl | |
- run: "cargo build --release --target x86_64-unknown-linux-musl" | |
- name: Build archive | |
shell: bash | |
run: | | |
dirname="ocpp-csms-server-${{ env.VERSION }}-x86_64-unknown-linux-musl" | |
mkdir "$dirname" | |
mv "target/x86_64-unknown-linux-musl/release/ocpp" "$dirname" | |
mv "target/x86_64-unknown-linux-musl/release/api" "$dirname" | |
tar -czf "$dirname.tar.gz" "$dirname" | |
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV | |
- uses: AButler/upload-release-assets@v3.0 | |
with: | |
files: "ocpp-csms-server-${{ env.VERSION }}-x86_64-unknown-linux-musl.tar.gz" | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
release-tag: v${{ needs.get-tag.outputs.pkg-version }} | |
push-to-registry: | |
name: "Push Docker image to Docker Hub" | |
needs: | |
- "get-tag" | |
- "upload-assets" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Check out the repo" | |
uses: actions/checkout@v3 | |
- name: "Log in to Github Packages" | |
uses: "docker/login-action@v2" | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Extract metadata (tags, labels) for Docker" | |
id: "meta" | |
uses: "docker/metadata-action@v4" | |
with: | |
images: ${{ env.IMAGE_NAME }} | |
- name: "Build and push Docker image" | |
uses: "docker/build-push-action@v3" | |
with: | |
context: . | |
push: true | |
tags: ${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:v${{ needs.get-tag.outputs.pkg-version }} | |
labels: ${{ steps.meta.outputs.labels }} |