Merge pull request #159 from BrenekH/dependabot/npm_and_yarn/frontend… #380
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: Controller CI/CD | |
on: push | |
jobs: | |
test: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: ["ubuntu-latest"] | |
go-version: ["1.17", "1.18"] | |
defaults: | |
run: | |
working-directory: ./controller | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Run tests | |
env: | |
# We aim to be CGO free to improve compatibility. Disabling it in the CI should help with that goal. | |
CGO_ENABLED: 0 | |
ENCODARR_CONFIG_DIR: ${{ runner.temp }} | |
run: go test ./... | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: ["ubuntu-latest"] | |
go-version: ["1.18"] | |
go-os-arch: | |
[ | |
"linux/amd64", | |
"linux/arm64", | |
"linux/arm", | |
"windows/amd64", | |
"darwin/amd64", | |
"darwin/arm64", | |
] | |
defaults: | |
run: | |
working-directory: ./controller | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Compute GOOS and GOARCH | |
env: | |
IFS: "/" | |
run: | | |
echo "COMP_GOOS=$(echo ${{ matrix.go-os-arch }} | cut -d/ -f1 -)" >> $GITHUB_ENV | |
echo "COMP_GOARCH=$(echo ${{ matrix.go-os-arch }} | cut -d/ -f2 -)" >> $GITHUB_ENV | |
- name: Set suffix (windows) | |
if: contains(matrix.go-os-arch, 'windows') | |
run: echo "EXEC_SUFFIX=.exe" >> $GITHUB_ENV | |
- name: Set suffix (literally everything else) | |
if: "!contains(matrix.go-os-arch, 'windows')" | |
run: echo "EXEC_SUFFIX=$("")" >> $GITHUB_ENV | |
- name: Set version for ldflags (tag ref) | |
if: startsWith(github.ref, 'refs/tags/') | |
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV | |
- name: Set version for ldflags (non-tag ref) | |
if: "!startsWith(github.ref, 'refs/tags/')" | |
# Makes the embedded version "{branch-name}-development" | |
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:11})-development" >> $GITHUB_ENV | |
- name: Build executable | |
env: | |
# We aim to be CGO free to improve compatibility. Disabling it in the CI should help with enforcing that goal. | |
CGO_ENABLED: 0 | |
GOARM: 7 | |
GOOS: ${{ env.COMP_GOOS }} | |
GOARCH: ${{ env.COMP_GOARCH }} | |
run: go build -o encodarr-controller-${{ env.COMP_GOOS }}-${{ env.COMP_GOARCH }}${{ env.EXEC_SUFFIX }} -ldflags="-X 'github.com/BrenekH/encodarr/controller/globals.Version=${{ env.LDFLAGS_VERSION }}'" cmd/main.go | |
- name: Upload artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: encodarr-controller-${{ env.COMP_GOOS }}-${{ env.COMP_GOARCH }}${{ env.EXEC_SUFFIX }} | |
path: ${{ github.workspace }}/controller/encodarr-controller-${{ env.COMP_GOOS }}-${{ env.COMP_GOARCH }}${{ env.EXEC_SUFFIX }} | |
deploy-container-images-tags: | |
runs-on: ubuntu-latest | |
needs: [test, build] | |
if: github.repository_owner == 'BrenekH' && github.actor != 'dependabot[bot]' # Ensure secrets are defined | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Generate Docker Metadata | |
id: meta | |
uses: crazy-max/ghaction-docker-meta@v2 | |
with: | |
images: | | |
brenekh/encodarr-controller | |
ghcr.io/brenekh/encodarr-controller | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-controller-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-controller-buildx- | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set version for ldflags (tag ref) | |
if: startsWith(github.ref, 'refs/tags/') | |
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV | |
- name: Set version for ldflags (non-tag ref) | |
if: "!startsWith(github.ref, 'refs/tags/')" | |
# Makes the embedded version "{branch-name}-development" | |
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:11})-development" >> $GITHUB_ENV | |
- name: Build and push container images/tags | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./controller | |
push: true | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
build-args: LDFLAGS_VERSION=${{ env.LDFLAGS_VERSION }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Move cache | |
# Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
upload-binaries-to-gh-releases: | |
runs-on: ubuntu-latest | |
needs: [test, build] | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
path: ${{ github.workspace }}/build-artifacts | |
- name: Upload to release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ${{ github.workspace }}/build-artifacts/*/* | |
tag: ${{ github.ref }} | |
overwrite: true | |
file_glob: true |