infracost_atlantis #164
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: Create Atlantis release | |
on: | |
workflow_dispatch: | |
repository_dispatch: | |
types: [infracost_atlantis] | |
jobs: | |
generate-release-matrix: | |
name: Generate release matrix | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- id: set-matrix | |
name: Set matrix | |
shell: bash | |
run: | | |
cli=$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -s https://api.github.com/repos/infracost/infracost/releases | jq -r '[.[].tag_name] | map(capture("^v(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)\\.(?<patch>0|[1-9]\\d*)$")) | map({version: "\(.major).\(.minor).\(.patch)", group: "\(.major).\(.minor)", major: .major | tonumber, minor: .minor | tonumber, patch: .patch | tonumber}) | map(select(.minor >= 9)) | group_by(.group) | map (.[0]) | sort_by(.major, .minor, .patch) | reverse | .[:2] | . as $result | map({cli_version: .version, cli_release: .group, latest: (.version == $result[0].version)}) | tostring') | |
atlantis=$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -s https://api.github.com/repos/runatlantis/atlantis/releases\?per_page\=100 | jq -r '[.[].tag_name] | map(capture("^v(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)\\.(?<patch>0|[1-9]\\d*)$")) | map({version: "\(.major).\(.minor).\(.patch)", group: "\(.major).\(.minor)", major: .major | tonumber, minor: .minor | tonumber, patch: .patch | tonumber}) | group_by(.group) | map (.[0]) | sort_by(.major, .minor, .patch) | reverse | .[:2] | . as $result | map({atlantis_version: .version, atlantis_release: .group, latest: (.version == $result[0].version)}) | tostring') | |
matrix=$(jq --argjson atlantis $atlantis --argjson cli $cli -n -c '$atlantis | reduce .[] as $x ([]; . + [$cli | map (. + $x + {latest: (.latest and $x.latest)})]) | flatten | {include: .}') | |
echo $matrix | |
echo "::set-output name=matrix::$matrix" | |
build: | |
name: Create release for Atlantis ${{ matrix.atlantis_version}}, Infracost ${{ matrix.cli_version }} | |
needs: generate-release-matrix | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.generate-release-matrix.outputs.matrix)}} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: infracost/infracost-atlantis | |
flavor: | | |
latest=${{ matrix.latest }} | |
tags: | | |
type=raw,value=atlantis${{ matrix.atlantis_release }}-infracost${{ matrix.cli_release }} | |
labels: | | |
atlantis-version=${{ matrix.atlantis_version }} | |
cli-version=${{ matrix.cli_version }} | |
- name: Build and push Docker images | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
version=v${{ matrix.atlantis_version }} | |
cli_version=v${{ matrix.cli_release }} | |
push: true |