Skip to content

Build Missing Tags and Branches #20798

Build Missing Tags and Branches

Build Missing Tags and Branches #20798

name: Build Missing Tags and Branches
on:
schedule:
- cron: "30 * * * *"
workflow_dispatch:
jobs:
fetch:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.fetch.outputs.matrix }}
empty_matrix: ${{ steps.check-matrix.outputs.empty_matrix }}
steps:
- uses: actions/checkout@v3
- id: fetch
run: |
dockerApiToken="$(curl --silent --get --data-urlencode service=registry.docker.io --data-urlencode scope=repository:fischerscode/flutter-sudo:pull https://auth.docker.io/token | jq --raw-output '.token')"
curl --silent --get -H "Accept: application/json" -H "Authorization: Bearer $dockerApiToken" https://registry-1.docker.io/v2/fischerscode/flutter-sudo/tags/list | jq '.tags' > dockerhub-tags.json
cat dockerhub-tags.json ignored_tags.json | jq -s 'map(.[])' > existing-tags.json
curl -s https://api.github.com/repos/flutter/flutter/git/refs/tags | jq 'map(.ref) | map(sub("refs/tags/"; "")) | .[]' > availiable_tags.json
curl -s https://api.github.com/repos/flutter/flutter/git/refs/heads | jq 'map(.ref) | map(sub("refs/heads/"; "")) | .[]' > availiable_branches.json
matrix=$(cat availiable_tags.json availiable_branches.json | xargs -L1 -I TAG sh -c "cat existing-tags.json | jq 'select(all(.[]; .==(\"TAG\" | sub(\"\\\\+\"; \"_\"; \"g\")) | not)) | \"TAG\"'" | jq -s '.[:20]' | jq -c '{channel: . , include: map({channel: . , tags: [ if . == "stable" then ., "latest" else . end ]})}')
echo "::set-output name=matrix::$matrix"
- name: Check matrix
id: check-matrix
run: |
echo "::set-output name=empty_matrix::$(echo '${{ steps.fetch.outputs.matrix }}' | jq '.channel | length > 0 | not')"
build:
needs: fetch
runs-on: ubuntu-latest
if: ${{ needs.fetch.outputs.empty_matrix == 'false' }}
strategy:
matrix: ${{fromJson(needs.fetch.outputs.matrix)}}
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: setup buildx
uses: docker/setup-buildx-action@v3.0.0
with:
install: true
- name: Login to Docker Hub
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image
run: |
docker build \
-t fischerscode/flutter:$(echo ${{ join(matrix.tags, ' | tr + _) -t fischerscode/flutter:$(echo ') }} | tr + _) \
--build-arg=flutterVersion=${{ matrix.channel }} \
--cache-from=type=registry,ref=fischerscode/flutter-cache:$(echo ${{ matrix.channel }} | tr + _) \
--cache-to=type=registry,ref=fischerscode/flutter-cache:$(echo ${{ matrix.channel }} | tr + _),mode=max \
--push \
--platform linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x \
.
- name: Build and push sudo image
run: |
docker build \
-t fischerscode/flutter-sudo:$(echo ${{ join(matrix.tags, ' | tr + _) -t fischerscode/flutter-sudo:$(echo ') }} | tr + _) \
--build-arg=flutterVersion=${{ matrix.channel }} \
--push \
--platform linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x \
-f Dockerfile.sudo \
.