👷 #91: Build Windows images #68
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 | |
on: | |
push: | |
tags: | |
- "*" | |
pull_request: | |
types: | |
- synchronize | |
- labeled | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
dry-run: ${{ steps.build-context.outputs.dry-run }} | |
version: ${{ steps.build-context.outputs.version }} | |
commit: ${{ steps.build-context.outputs.commit }} | |
build_date: ${{ steps.build-context.outputs.build_date }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set build context | |
id: build-context | |
run: | | |
LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}" | |
DRY_RUN="false" | |
if [[ $LABELS == *"build:dry-run"* ]]; then | |
DRY_RUN="true" | |
fi | |
echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT | |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then | |
PR_ID=$(echo ${{ github.ref }} | cut -d '/' -f 3) | |
echo "version=dev.$PR_ID" >> $GITHUB_OUTPUT | |
else | |
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
fi | |
echo "commit=$(git rev-parse --short '$GITHUB_SHA')" >> $GITHUB_OUTPUT | |
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT | |
# lint: | |
# uses: ./.github/workflows/lint.yaml | |
# vuln: | |
# uses: ./.github/workflows/vuln.yaml | |
release: | |
if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" | |
needs: | |
- setup | |
# - lint | |
# - vuln | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.22 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Snapcraft Setup | |
run: | | |
sudo apt-get update | |
sudo apt-get -yq --no-install-suggests --no-install-recommends install snapcraft | |
mkdir -p $HOME/.cache/snapcraft/download | |
mkdir -p $HOME/.cache/snapcraft/stage-packages | |
- name: Prepare GoReleaser extra args | |
run: | | |
ARGS="" | |
if [[ "${{ needs.setup.outputs.dry-run }}" == "true" ]]; then | |
ARGS="$ARGS --skip=validate --skip=publish" | |
fi | |
echo "GORELEASER_EXTRA_ARGS=$ARGS" >> $GITHUB_ENV | |
# - name: Run GoReleaser | |
# uses: goreleaser/goreleaser-action@v5 | |
# with: | |
# distribution: goreleaser | |
# version: latest | |
# args: release --clean ${{ env.GORELEASER_EXTRA_ARGS }} | |
# env: | |
# GORELEASER_DRY_RUN: ${{ env.GORELEASER_DRY_RUN }} | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }} | |
# DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} | |
# DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} | |
# BREW_TAP_PRIVATE_KEY: ${{ secrets.BREW_TAP_PRIVATE_KEY }} | |
images-linux: | |
if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" | |
strategy: | |
matrix: | |
image: | |
- alpine | |
- ubuntu | |
- distroless | |
- redhat | |
runs-on: ubuntu-latest | |
needs: | |
- release | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: login into Github Container Registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- name: login into Docker | |
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin | |
- name: build ${{ matrix.image }} image | |
working-directory: ./images | |
env: | |
VERSION: ${{ needs.setup.outputs.version }} | |
COMMIT: ${{ needs.setup.outputs.commit }} | |
BUILD_DATE: ${{ needs.setup.outputs.build_date }} | |
run: VERSION="${{ env.VERSION }}" COMMIT="${{ env.COMMIT }}" BUILD_DATE="${{ env.BUILD_DATE }}" make ${{ matrix.image }} | |
- name: publish ${{ matrix.image }} image to Github Container Registry | |
if: "needs.setup.outputs.dry-run != 'true'" | |
working-directory: ./images | |
env: | |
VERSION: ${{ needs.setup.outputs.version }} | |
run: VERSION="${{ env.VERSION }}" make publish-ghcr-${{ matrix.image }} | |
- name: publish ${{ matrix.image }} image to DockerHub | |
if: "needs.setup.outputs.dry-run != 'true'" | |
working-directory: ./images | |
env: | |
VERSION: ${{ needs.setup.outputs.version }} | |
run: VERSION="${{ env.VERSION }}" make publish-dockerhub-${{ matrix.image }} | |
images-win: | |
if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" | |
strategy: | |
matrix: | |
image: | |
- nanoserver | |
- windows-server | |
needs: | |
- release | |
runs-on: windows-2019 | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: login into Github Container Registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- name: login into Docker | |
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin | |
- name: build ${{ matrix.image }} image | |
working-directory: ./images | |
env: | |
VERSION: ${{ needs.setup.outputs.version }} | |
COMMIT: ${{ needs.setup.outputs.commit }} | |
BUILD_DATE: ${{ needs.setup.outputs.build_date }} | |
run: VERSION="${{ env.VERSION }}" COMMIT="${{ needs.setup.outputs.commit }}" BUILD_DATE="${{ needs.setup.outputs.build_date }}" make ${{ matrix.image }} | |
- name: publish ${{ matrix.image }} image to Github Container Registry | |
if: "needs.setup.outputs.dry-run != 'true'" | |
working-directory: ./images | |
env: | |
VERSION: ${{ needs.setup.outputs.version }} | |
run: VERSION="${{ env.VERSION }}" make publish-ghcr-${{ matrix.image }} | |
- name: publish ${{ matrix.image }} image to DockerHub | |
if: "needs.setup.outputs.dry-run != 'true'" | |
working-directory: ./images | |
env: | |
VERSION: ${{ needs.setup.outputs.version }} | |
run: VERSION="${{ env.VERSION }}" make publish-dockerhub-${{ matrix.image }} |