updating workflow action version and multi-arch support #24
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: Build and Deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: ["main"] | |
jobs: | |
build: | |
environment: main | |
env: | |
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} | |
runs-on: ubuntu-latest | |
outputs: | |
tags: ${{ steps.set_latest_tag.outputs.tags }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Install musl cc | |
uses: awalsh128/cache-apt-pkgs-action@v1 | |
with: | |
packages: musl-tools musl-dev musl | |
- name: Setup Go with Caching | |
uses: actions/setup-go@v4 | |
with: | |
go-version-file: './go.mod' | |
cache: true | |
- name: Tag Version | |
id: tag_version | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GH_ACCESS_TOKEN }} | |
release_branches: main | |
tag_prefix: v | |
- name: Configure Git for Private Repos | |
run: | | |
git config --global url.https://[email protected]/opengovern.insteadOf https://github.com/opengovern | |
- name: Build Local Task App | |
run: make local-build | |
- name: Pack Local Task Build | |
run: tar -cvf local.tar local | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: og-task-grype | |
path: ./local.tar | |
retention-days: 1 | |
- name: Set Latest Tag Output | |
id: set_latest_tag | |
run: | | |
if [[ -z "${{ steps.tag_version.outputs.new_tag }}" ]]; then | |
# No new tag found, only use previous_tag without latest | |
echo "tags=ghcr.io/${{ github.repository_owner }}/og-task-grype:${{ steps.tag_version.outputs.previous_tag }}" >> "$GITHUB_OUTPUT" | |
else | |
# New tag found, use new_tag and latest | |
echo "tags=ghcr.io/${{ github.repository_owner }}/og-task-grype:${{ steps.tag_version.outputs.new_tag }} ghcr.io/${{ github.repository_owner }}/og-task-grype:latest" >> "$GITHUB_OUTPUT" | |
fi | |
deploy-task: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
packages: write | |
environment: main | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: og-task-grype | |
path: . | |
- name: Unpack Task Artifact | |
run: tar -xvf local.tar | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and Push Docker Image (Multi-Arch) | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: ${{ needs.build.outputs.tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |