WIP: GitHub Action #7
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: CI/CD | |
on: | |
push: | |
branches: | |
- "**" | |
tags: | |
- 'v*.*.*' | |
pull_request: | |
branches: | |
- "master" | |
env: | |
IMAGE_NAME: ingv/fdsnws-fetcher | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build Docker image | |
run: | | |
IMAGE_TAG=${GITHUB_REF#refs/tags/v} | |
docker build --no-cache --pull --tag ${{ env.IMAGE_NAME }}:latest . | |
- name: Save Docker image to file | |
run: | | |
docker save -o image.tar ${{ env.IMAGE_NAME }} | |
- name: Upload Docker image | |
uses: actions/upload-artifact@v4 | |
with: | |
name: docker-image | |
path: image.tar | |
- name: Upload README.md | |
uses: actions/upload-artifact@v4 | |
with: | |
name: readme | |
path: README.md | |
publish-tag-and-latest: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Docker image | |
uses: actions/download-artifact@v4 | |
with: | |
name: docker-image | |
path: /tmp | |
- name: Download README.md | |
uses: actions/download-artifact@v4 | |
with: | |
name: readme | |
path: /tmp | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Load Docker image | |
run: docker load -i /tmp/image.tar | |
- name: Tag and push Docker image | |
run: | | |
IMAGE_TAG=${GITHUB_REF#refs/tags/v} | |
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG | |
docker push $IMAGE_NAME:latest | |
docker push $IMAGE_NAME:$IMAGE_TAG | |
- name: Publish Docker description (README.md) to Docker Hub | |
run: | | |
wget -O docker-pushrm "https://github.com/christian-korneck/docker-pushrm/releases/download/v1.7.0/docker-pushrm_linux_amd64" | |
chmod +x docker-pushrm | |
./docker-pushrm --file README.md ${{ env.IMAGE_NAME }} | |
test-publiccode: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Run publiccode parser | |
run: | | |
docker run -i --rm italia/publiccode-parser-go /dev/stdin < publiccode.yml |