Skip to content

PANDARIA: fix release ci workflow #67

PANDARIA: fix release ci workflow

PANDARIA: fix release ci workflow #67

Workflow file for this run

name: release
on:
push:
tags:
- v*
workflow_dispatch:
permissions:
contents: write
env:
REGISTRY: registry.rancher.cn
REPO: cnrancher
OAUTH_TOKEN: ${{ secrets.RD_ONLY_GH_TOKEN }}
jobs:
build:
name: build and package
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- amd64
- arm64
steps:
- name : Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Build Binary
run: |
./scripts/build
mkdir -p dist/artifacts
cp bin/webhook dist/artifacts/webhook-linux-${{ matrix.arch }}
env:
ARCH: "${{ matrix.arch}}"
GOARCH: "${{ matrix.arch}}"
- name: Prepare Artifacts
run: |
mkdir -p dist/artifacts
cp bin/webhook dist/artifacts/webhook-linux-${{ matrix.arch }}
cd dist/artifacts
sha256sum webhook-linux-${{ matrix.arch }} > sha256sum-${{ matrix.arch }}.txt
- name: Upload artifacts
# https://github.com/actions/upload-artifact/commit/65462800fd760344b1a7b4382951275a0abb4808
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: webhook-artifacts-${{ matrix.arch }}
path: |
dist/artifacts/webhook-linux-${{ matrix.arch }}
dist/artifacts/sha256sum-${{ matrix.arch }}.txt
dist/artifacts/rancher-webhook-*.tgz
release:
needs: build
runs-on: ubuntu-latest
steps:
- name : Checkout repository
# https://github.com/actions/checkout/releases/tag/v4.1.1
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: package-helm
run: make package-helm
- name: Download the amd64 artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
# https://github.com/actions/download-artifact/releases/tag/v4.1.7
with:
name: webhook-artifacts-amd64
path: dist/artifacts
- name: Download the arm64 artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
# https://github.com/actions/download-artifact/releases/tag/v4.1.7
with:
name: webhook-artifacts-arm64
path: dist/artifacts
- name: Get the version
run: |
source ./scripts/version
echo "TAG=$(echo $TAG | sed 's/-amd64$//')" >> $GITHUB_ENV
- name: Upload the files
run: |
ls -lR dist
cd dist/artifacts
gh --repo "${{ github.repository }}" release create ${{ github.ref_name }} --prerelease --verify-tag --generate-notes webhook-linux-* sha256sum-*.txt rancher-webhook*.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
image:
permissions:
contents: read
id-token: write
strategy:
matrix:
arch:
- amd64
- arm64
name: Build and push Webhook images
runs-on: ubuntu-latest
needs: build
steps:
- name : Checkout repository
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Download the artifacts
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: webhook-artifacts-${{ matrix.arch }}
path: dist/artifacts
- name: Move binary to bin/
run: |
mkdir -p bin/
cp -v dist/artifacts/webhook-linux-${{ matrix.arch }} bin/webhook
chmod +x bin/webhook
- name: Set up QEMU
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Log in to the Container registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.TCR_USERNAME }}
password: ${{ secrets.TCR_TOKEN }}
- name: Set Version/Commit
run: |
source ./scripts/version
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "COMMIT=${COMMIT}" >> $GITHUB_ENV
- name: Build and push the webhook image
id: build
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
file: ./package/Dockerfile
secrets: |
token=${{ secrets.RD_ONLY_GH_TOKEN }}
platforms: "linux/${{ matrix.arch }}"
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.REPO }}/rancher-webhook,push-by-digest=true,name-canonical=true,push=true
build-args: |
VERSION=${{ env.VERSION }}
COMMIT=${{ env.COMMIT }}
GOPRIVATE=github.com/cnrancher
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: digests-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
permissions:
id-token: write
runs-on: ubuntu-latest
needs: image
steps:
- name: Download digests
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Log in to the Container registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.TCR_USERNAME }}
password: ${{ secrets.TCR_TOKEN }}
- if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
echo TAG_NAME=$(echo $GITHUB_REF | sed -e "s|refs/tags/||") >> $GITHUB_ENV
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.REPO }}/rancher-webhook:${{ env.TAG_NAME }} \
$(printf '${{ env.REGISTRY }}/${{ env.REPO }}/rancher-webhook@sha256:%s ' *)
image-sign:
permissions:
contents: read
id-token: write # required for hangar sign OIDC keyless mode
runs-on: ubuntu-latest
needs: [ merge ]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name}}
- name: Login to TCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.TCR_USERNAME }}
password: ${{ secrets.TCR_TOKEN }}
- name: Hangar Sign
uses: cnrancher/hangar/.github/actions/hangar-sign@main
with:
version: v1.9.0
images: |
${{ vars.REGISTRY }}/${{ env.REPO }}/rancher-webhook:${{ github.ref_name }}