diff --git a/.github/workflows/pr-release.yml b/.github/workflows/pr-release.yml index 9b73844..00486ca 100644 --- a/.github/workflows/pr-release.yml +++ b/.github/workflows/pr-release.yml @@ -1,4 +1,4 @@ -# Thanks to https://github.com/museofficial/muse/blob/master/.github/workflows/pr-snapshot.yml for this amazing workflow. +# Thanks to https://github.com/museofficial/muse/blob/master/.github/workflows/pr-release.yml for this amazing workflow. name: Release snapshot of PR on: @@ -8,7 +8,7 @@ on: - completed env: - REGISTRY_IMAGE: ghcr.io/seijinmark/EveryoneShouldKnow + REGISTRY_IMAGE: ghcr.io/seijinmark/esk jobs: release-and-comment: diff --git a/.github/workflows/pr-snapshot.yml b/.github/workflows/pr-snapshot.yml new file mode 100644 index 0000000..0077b72 --- /dev/null +++ b/.github/workflows/pr-snapshot.yml @@ -0,0 +1,103 @@ +# Thanks to https://github.com/museofficial/muse/blob/master/.github/workflows/pr-snapshot.yml for this amazing workflow. + +name: Build snapshot of PR + +on: pull_request + +env: + REGISTRY_IMAGE: ghcr.io/seijinmark/esk + +jobs: + build: + name: Build snapshot + strategy: + matrix: + runner-platform: + - ubuntu-latest + - namespace-profile-default-arm64 + include: + - runner-platform: ubuntu-latest + build-arch: linux/amd64 + - runner-platform: namespace-profile-default-arm64 + build-arch: linux/arm64 + runs-on: ${{ matrix.runner-platform }} + steps: + - name: Prepare + run: | + platform=${{ matrix.build-arch }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: type=ref,event=pr + + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get current time + uses: josStorer/get-current-time@v2 + id: current-time + + - name: Build + id: build + uses: docker/build-push-action@v6 + with: + outputs: type=docker,dest=/tmp/image-${{ env.PLATFORM_PAIR }}.tar + platforms: ${{ matrix.build-arch }} + tags: | + ${{ env.REGISTRY_IMAGE }}:${{ github.sha }}-${{ env.PLATFORM_PAIR }} + build-args: | + COMMIT_HASH=${{ github.sha }} + BUILD_DATE=${{ steps.current-time.outputs.time }} + + - name: Export Docker meta output + shell: bash + run: echo $DOCKER_METADATA_OUTPUT_JSON > /tmp/metadata.json + + - name: Upload metadata + uses: actions/upload-artifact@v4 + with: + name: metadata + path: /tmp/metadata.json + overwrite: true + + - name: Export SHA + run: | + echo "${{ github.sha }}" > /tmp/sha.txt + + - name: Upload SHA + uses: actions/upload-artifact@v4 + with: + name: sha + path: /tmp/sha.txt + overwrite: true + + - name: Upload image + uses: actions/upload-artifact@v4 + with: + name: image-${{ env.PLATFORM_PAIR }} + path: /tmp/image-${{ env.PLATFORM_PAIR }}.tar + if-no-files-found: error + retention-days: 1 + + - name: Save PR number in artifact + shell: bash + env: + PR_NUMBER: ${{ github.event.number }} + run: echo $PR_NUMBER > /tmp/pull_request_number.txt + - name: Upload PR number + uses: actions/upload-artifact@v4 + with: + name: pull_request_number + path: /tmp/pull_request_number.txt + overwrite: true \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..009b5e8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,149 @@ +# Thanks to https://github.com/museofficial/muse/blob/master/.github/workflows/publish.yml for this amazing workflow. + +name: Make release & publish Docker image + +on: + push: + tags: + - 'v*' + +env: + REGISTRY_IMAGE: ghcr.io/seijinmark/esk + +jobs: + publish: + strategy: + matrix: + runner-platform: + - ubuntu-latest + - namespace-profile-default-arm64 + include: + - runner-platform: ubuntu-latest + build-arch: linux/amd64 + tagged-platform: amd64 + - runner-platform: namespace-profile-default-arm64 + build-arch: linux/arm64 + tagged-platform: arm64 + runs-on: ${{ matrix.runner-platform }} + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get current time + uses: josStorer/get-current-time@v2 + id: current-time + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v6 + with: + push: true + tags: | + seijinmark/esk:${{ github.sha }}-${{ matrix.tagged-platform }} + ${{ env.REGISTRY_IMAGE }}:${{ github.sha }}-${{ matrix.tagged-platform }} + platforms: ${{ matrix.build-arch }} + build-args: | + COMMIT_HASH=${{ github.sha }} + BUILD_DATE=${{ steps.current-time.outputs.time }} + + combine: + name: Combine platform tags + runs-on: ubuntu-latest + needs: publish + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - uses: actions/checkout@v1 + + - name: Set up Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get tags (Docker Hub) + id: get-tags-dockerhub + uses: Surgo/docker-smart-tag-action@v1 + with: + docker_image: seijinmark/esk + + - name: Get tags (ghcr.io) + id: get-tags-ghcr + uses: Surgo/docker-smart-tag-action@v1 + with: + docker_image: ${{ env.REGISTRY_IMAGE }} + + - name: Combine tags (Docker Hub) + run: docker buildx imagetools create $(echo '${{ steps.get-tags-dockerhub.outputs.tag }}' | tr "," "\0" | xargs -0 printf -- '-t %s ') 'seijinmark/esk:${{ github.sha }}-arm64' 'seijinmark/esk:${{ github.sha }}-amd64' + + - name: Combine tags (GitHub Container Registry) + run: docker buildx imagetools create $(echo '${{ steps.get-tags-ghcr.outputs.tag }}' | tr "," "\0" | xargs -0 printf -- '-t %s ') '${{ env.REGISTRY_IMAGE }}:${{ github.sha }}-arm64' '${{ env.REGISTRY_IMAGE }}:${{ github.sha }}-amd64' + + - name: Update Docker Hub description + uses: peter-evans/dockerhub-description@v2.4.3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + repository: seijinmark/esk + + release: + name: Create GitHub release + runs-on: ubuntu-latest + needs: combine + steps: + - uses: actions/checkout@v2 + + - name: Get version from tag + id: tag_name + run: | + echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v} + shell: bash + + - name: Get Changelog Entry + id: changelog_reader + uses: mindsers/changelog-reader-action@v2 + with: + version: ${{ steps.tag_name.outputs.current_version }} + path: ./CHANGELOG.md + + - name: Create/update release + uses: ncipollo/release-action@v1 + with: + tag: v${{ steps.changelog_reader.outputs.version }} + name: Release v${{ steps.changelog_reader.outputs.version }} + body: ${{ steps.changelog_reader.outputs.changes }} + prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }} + draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }} + allowUpdates: true + token: ${{ secrets.GH_PAT }} \ No newline at end of file