Docker #131
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: Docker | |
on: | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
- cron: '30 23 * * *' | |
workflow_dispatch: | |
push: | |
# Publish `main` as Docker `latest` image. | |
branches: | |
- main | |
paths-ignore: | |
- ".github/**" | |
# Publish `v1.2.3` tags as releases. | |
tags: | |
- v* | |
# Run tests for any PRs. | |
pull_request: | |
env: | |
IMAGE_NAME: arm-gcc-none-eabi-toolchain | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run tests | |
run: | | |
if [ -f docker-compose.test.yml ]; then | |
docker-compose --file docker-compose.test.yml build | |
docker-compose --file docker-compose.test.yml run sut | |
else | |
docker build . --file Dockerfile | |
fi | |
push: | |
# Ensure test job passes before pushing image. | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.event_name != 'pull_request' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build image | |
run: docker build . --file Dockerfile --tag image | |
- name: Dockerhub Login | |
uses: docker/#-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Push image | |
run: | | |
IMAGE_ID=letssteam/$IMAGE_NAME | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
docker tag image $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION | |
trigger: | |
needs: push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Trigger Workflow in Another Repository | |
run: | | |
# Set the required variables | |
repo_owner="letssteam" | |
repo_name="makecode-toolchain-docker" | |
event_type="trigger-workflow" | |
curl -L \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.ACTION_TOKEN }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$repo_owner/$repo_name/dispatches \ | |
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"unit\": false, \"integration\": true}}" |