Update docker-image.yml #132
Workflow file for this run
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 Image CI | |
on: | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
create_release: | |
permissions: write-all | |
name: Create Github Release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v2 | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1.1.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
draft: true | |
prerelease: false | |
- name: Output Release URL File | |
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt | |
- name: Save Release URL File for publish | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release_url | |
path: release_url.txt | |
build_artifact: | |
needs: [create_release] | |
name: ${{ matrix.os }}/GHC ${{ matrix.ghc }}/${{ github.ref }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macOS-latest, windows-latest] | |
ghc: | |
- "9.8.2" | |
cabal: ["3.10.3.0"] | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v2 | |
- name: Set tag name | |
uses: olegtarasov/get-tag@v2.1.3 | |
id: tag | |
with: | |
tagRegex: "v(.*)" | |
tagRegexGroup: 1 | |
- name: Setup Haskell | |
uses: haskell-actions/setup@v2 | |
id: setup-haskell-cabal | |
with: | |
ghc-version: ${{ matrix.ghc }} | |
cabal-version: ${{ matrix.cabal }} | |
- name: Freeze | |
run: | | |
cabal freeze | |
- name: Cache ~/.cabal/store | |
uses: actions/cache@v1 | |
with: | |
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} | |
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} | |
- name: Build binary | |
run: | | |
mkdir dist | |
cabal install Hastructure --install-method=copy --overwrite-policy=always --installdir=dist | |
- if: matrix.os == 'windows-latest' | |
name: Set binary path name on windows | |
run: echo "BINARY_PATH=./dist/Hastructure.exe" >> $GITHUB_ENV | |
- if: matrix.os != 'windows-latest' | |
name: Set binary path name on windows | |
run: echo "BINARY_PATH=./dist/Hastructure-exe" >> $GITHUB_ENV | |
- name: Load Release URL File from release job | |
uses: actions/download-artifact@v4 | |
with: | |
name: release_url | |
path: release_url | |
# See Note [environment variables] | |
- if: matrix.os != 'windows-latest' | |
name: Get Release File Name & Upload URL not on Widows | |
run: | | |
echo "upload_url=$(cat release_url/release_url.txt)" >> $GITHUB_ENV | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1.0.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ env.upload_url }} | |
asset_path: ${{ env.BINARY_PATH }} | |
asset_name: Hastructure-${{ steps.tag.outputs.tag }}-${{ runner.os }}-ghc-${{ matrix.ghc }}${{ env.EXT }} | |
asset_content_type: application/octet-stream | |
build: | |
needs: [build_artifact] | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Login to Docker Hub | |
uses: docker/#-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PW }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
with: | |
images: yellowbean/hastructure | |
- name: 'Cleanup build folder' | |
run: | | |
ls -la ./ | |
rm -rf ./* || true | |
rm -rf ./.??* || true | |
ls -la . | |
rm -rf /opt/ghc | |
rm -rf /opt/hostedtoolcache | |
- | |
name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/hastructure:latest, ${{ steps.meta.outputs.tags }} | |
cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/hastructure:buildcache | |
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/hastructure:buildcache,mode=max | |