Pull before pushing in github workflows #195
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 Push | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- "action.yml" | |
- "README.md" | |
- "website/**" | |
permissions: | |
packages: write | |
contents: write | |
jobs: | |
generate-version: | |
runs-on: ubuntu-latest | |
outputs: | |
trunkver: ${{ steps.trunkver.outputs.trunkver }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Generate trunkver | |
id: trunkver | |
uses: crftd-tech/trunkver@main | |
with: | |
baseVersion: "1.0.0" | |
prerelease: "true" | |
build-release: | |
runs-on: ubuntu-latest | |
needs: [generate-version] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22 | |
- name: Build trunkver | |
env: | |
VERSION: ${{ needs.generate-version.outputs.trunkver }} | |
run: | | |
( | |
unset GITHUB_SHA | |
unset GITHUB_RUN_ID | |
make test all spec "VERSION=${VERSION}" | |
) | |
- name: Create release | |
id: release | |
uses: softprops/action-gh-release@v2 | |
if: github.ref == 'refs/heads/main' | |
with: | |
name: ${{ needs.generate-version.outputs.trunkver }} | |
tag_name: ${{ needs.generate-version.outputs.trunkver }} | |
files: | | |
out/trunkver* | |
build-docker: | |
runs-on: ubuntu-latest | |
needs: [generate-version] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Generate metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/crftd-tech/trunkver | |
tags: | | |
type=raw,value=${{ needs.generate-version.outputs.trunkver }} | |
type=raw,value=latest | |
- name: Log in to the Container registry | |
uses: docker/login-action@7ca345011ac4304463197fac0e56eab1bc7e6af0 | |
with: | |
registry: "ghcr.io" | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@7e094594beda23fc8f21fa31049f4b203e51096b | |
with: | |
context: . | |
push: ${{ github.ref == 'refs/heads/main' }} | |
build-args: | | |
VERSION=${{ needs.generate-version.outputs.trunkver }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Update the action.yml with the new image tag | |
if: github.ref == 'refs/heads/main' | |
run: | | |
yq eval --inplace '.runs.image = "docker://ghcr.io/crftd-tech/trunkver:${{ needs.generate-version.outputs.trunkver }}"' action.yml | |
git config --global user.email "bot@crftd.tech" | |
git config --global user.name "crftd-bot" | |
git add action.yml | |
git commit -m "chore: Bump image tag in action.yml" | |
git pull origin | |
git push origin |