Files
wonderwall/.github/workflows/deploy.yml
2022-05-19 08:24:09 +02:00

72 lines
2.4 KiB
YAML

name: Build wonderwall
on: [push]
env:
image_base: ghcr.io/${{ github.repository }}
jobs:
test:
runs-on: ubuntu-20.04
steps:
- name: Checkout latest code
uses: actions/checkout@v3
- name: Extract version of Go to use
run: echo "GOVERSION=$(cat go.mod | grep -w "go" | awk ' { print $2 } ' | grep -w "^[^v]")" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOVERSION }}
- name: Test Go
run: |
make test
build-and-deploy:
needs:
- test
name: Build, push and deploy
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Docker login
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: docker login ghcr.io -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN}
- name: Set version
run: |
echo "VERSION=$(./version.sh)" >> $GITHUB_ENV
- name: Build Docker image
run: |
docker build . --tag ${{ env.image_base }}:${{ env.VERSION }} --tag ${{ env.image_base }}:latest
- name: Push versioned docker image
run: |
docker push ${{ env.image_base }}:${{ env.VERSION }}
- name: Push latest docker image
if: github.ref == 'refs/heads/master'
run: docker push ${{ env.image_base }}:latest
- uses: navikt/github-app-token-generator@v1
id: get-token
if: github.ref == 'refs/heads/master'
with:
private-key: ${{ secrets.NAIS_APP_PRIVATE_KEY }}
app-id: ${{ secrets.NAIS_APP_ID }}
repo: navikt/nais-yaml
- name: Checkout nais-yaml
if: github.ref == 'refs/heads/master'
uses: actions/checkout@v3
with:
repository: navikt/nais-yaml
token: ${{ steps.get-token.outputs.token }}
path: nais-yaml
- name: Update nais-yaml
if: github.ref == 'refs/heads/master'
run: |
cd nais-yaml
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
sed -E -i "s#wonderwall_image:.+#wonderwall_image: ${{ env.image_base }}:${{ env.VERSION }}#" vars/global.yaml
git add .
git --no-pager diff --cached
git commit -a -m "Bump Wonderwall image version ${{ env.VERSION }}"
git push