Skip to content

Commit

Permalink
rework release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
nbusseneau committed May 14, 2024
1 parent 6c712a3 commit efc7ef6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 106 deletions.
87 changes: 41 additions & 46 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,88 +1,83 @@
name: Publish
name: Release
run-name: ${{ format('{0} {1}', inputs.is-dry-run && 'Dry-run' || 'Release', inputs.tag) }}

on:
workflow_dispatch:
inputs:
tag:
description: "Tag / Version number (leave empty for dry-run)"
required: false
description: "Tag / Version number"
is-dry-run:
description: "Dry-run (do not publish, only test build)"
type: boolean

permissions:
contents: write # required for pushing to the repository and creating releases

env:
changelog: CHANGELOG.md
source-dir: src/
artifacts-name: hades2-mod-template.zip
artifacts-content-type: application/zip
artifact-name: hades2-mod-template.zip
artifact-content-type: application/zip

jobs:
tag-and-release:
name: Rotate version, tag, and create release
release:
name: ${{ format('{0} {1}', inputs.is-dry-run && 'Dry-run' || 'Release', inputs.tag) }}
runs-on: ubuntu-latest
if: github.event.inputs.tag
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Check input tag format
run: |
echo "${{ github.event.inputs.tag }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$'
echo "${{ inputs.tag }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$'
- name: Checkout files
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
with:
lfs: true

- name: Rotate unreleased section in changelog
uses: thomaseizinger/keep-a-changelog-new-release@77ac767b2f7f6edf2ee72ab3364ed26667086f96
with:
tag: ${{ github.event.inputs.tag }}
tag: ${{ inputs.tag }}

- name: Build template
run: |
cd ${{ env.source-dir }}
zip ../${{ env.artifact-name }} -r .
- name: Upload artifact to workflow
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
name: ${{ env.artifact-name }}
path: ${{ env.artifact-name }}
retention-days: 1

- name: Push updated files to repository and tag
if: ${{ !inputs.is-dry-run }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ${{ env.changelog }}
git commit --message "Release ${{ github.event.inputs.tag }}"
git tag ${{ github.event.inputs.tag }}
git commit --message "Release ${{ inputs.tag }}"
git tag ${{ inputs.tag }}
git push origin HEAD:${{ github.ref_name }} --tags
- name: Create release
if: ${{ !inputs.is-dry-run }}
id: release
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e
with:
release_name: ${{ github.event.inputs.tag }}
tag_name: ${{ github.event.inputs.tag }}
release_name: ${{ inputs.tag }}
tag_name: ${{ inputs.tag }}
commitish: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-and-publish-artifacts:
name: Build and publish artifacts
needs: tag-and-release
if: always() && (needs.tag-and-release.result == 'success' || needs.tag-and-release.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout files
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
with:
ref: ${{ github.event.inputs.tag || github.sha }}
lfs: true

- name: Build artifacts
run: |
cd ${{ env.source-dir }}
zip ../${{ env.artifacts-name }} -r .
- name: Upload artifacts to workflow
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
name: ${{ env.artifacts-name }}
path: ${{ env.artifacts-name }}
retention-days: 1

- name: Upload artifacts to release
if: needs.tag-and-release.outputs.upload_url
- name: Upload artifact to release
if: ${{ !inputs.is-dry-run }}
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5
with:
upload_url: ${{ needs.tag-and-release.outputs.upload_url }}
asset_path: ${{ env.artifacts-name }}
asset_name: ${{ env.artifacts-name }}
asset_content_type: ${{ env.artifacts-content-type }}
upload_url: ${{ steps.release.outputs.upload_url }}
asset_name: ${{ env.artifact-name }}
asset_path: ${{ env.artifact-name }}
asset_content_type: ${{ env.artifact-content-type }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Streamline release workflow to make it fast-fail before tagging / releasing in case of build failure.

## [0.1.0] - 2024-04-24

### Added
Expand Down
113 changes: 53 additions & 60 deletions src/.github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,105 +1,98 @@
name: Publish
name: Release
run-name: ${{ format('{0} {1}', inputs.is-dry-run && 'Dry-run' || 'Release', inputs.tag) }}

on:
workflow_dispatch:
inputs:
tag:
description: "Tag / Version number (leave empty for dry-run)"
required: false
description: "Tag / Version number"
is-dry-run:
description: "Dry-run (do not publish, only test build)"
type: boolean

permissions:
contents: write # required for pushing to the repository and creating releases

env:
changelog: CHANGELOG.md
thunderstore-config: thunderstore.toml
build-dir: build/
artifacts-content-type: application/zip
artifact-content-type: application/zip

jobs:
tag-and-release:
name: Rotate version, tag, and create release
release:
name: ${{ format('{0} {1}', inputs.is-dry-run && 'Dry-run' || 'Release', inputs.tag) }}
runs-on: ubuntu-latest
if: github.event.inputs.tag
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Check input tag format
run: |
echo "${{ github.event.inputs.tag }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$'
echo "${{ inputs.tag }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$'
- name: Checkout files
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
with:
lfs: true

- name: Rotate unreleased section in changelog
uses: thomaseizinger/keep-a-changelog-new-release@77ac767b2f7f6edf2ee72ab3364ed26667086f96
with:
tag: ${{ github.event.inputs.tag }}
tag: ${{ inputs.tag }}

- name: Rotate version in Thunderstore CLI config
run: |
sed -i 's/versionNumber = ".*"/versionNumber = "${{ github.event.inputs.tag }}"/' ${{ env.thunderstore-config }}
sed -i 's/versionNumber = ".*"/versionNumber = "${{ inputs.tag }}"/' ${{ env.thunderstore-config }}
- name: Install Thunderstore CLI
run: dotnet tool install -g tcli

- name: Build package
run: |
tcli build
ARTIFACT_NAME=$(find "${{ env.build-dir }}" -type f -printf "%f\n")
echo "artifact-name=${ARTIFACT_NAME}" >> "$GITHUB_ENV"
echo "artifact-path=${{ env.build-dir }}/${{ env.artifact-name }}" >> "$GITHUB_ENV"
- name: Upload artifact to workflow
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
name: ${{ env.artifact-name }}
path: ${{ env.artifact-path }}
retention-days: 1

- name: Push updated files to repository and tag
- name: Tag and push to repository
if: ${{ !inputs.is-dry-run }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ${{ env.changelog }} ${{ env.thunderstore-config }}
git commit --message "Release ${{ github.event.inputs.tag }}"
git tag ${{ github.event.inputs.tag }}
git commit --message "Release ${{ inputs.tag }}"
git tag ${{ inputs.tag }}
git push origin HEAD:${{ github.ref_name }} --tags
- name: Publish package
if: ${{ !inputs.is-dry-run }}
env:
TCLI_AUTH_TOKEN: ${{ secrets.TCLI_AUTH_TOKEN }}
run: tcli publish --file ${{ env.artifact-path }}

- name: Create release
id: release
if: ${{ !inputs.is-dry-run }}
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e
with:
release_name: ${{ github.event.inputs.tag }}
tag_name: ${{ github.event.inputs.tag }}
release_name: ${{ inputs.tag }}
tag_name: ${{ inputs.tag }}
commitish: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-and-publish-package:
name: Build and publish package
needs: tag-and-release
if: always() && (needs.tag-and-release.result == 'success' || needs.tag-and-release.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout files
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
with:
ref: ${{ github.event.inputs.tag || github.sha }}
lfs: true

- name: Install Thunderstore CLI
run: dotnet tool install -g tcli

- name: Build package
if: ${{ !needs.tag-and-release.outputs.upload_url }}
run: tcli build

- name: Publish package
if: needs.tag-and-release.outputs.upload_url
env:
TCLI_AUTH_TOKEN: ${{ secrets.TCLI_AUTH_TOKEN }}
run: tcli publish

- name: Retrieve package name
run: |
ARTIFACTS_NAME=$(find "${{ env.build-dir }}" -type f -printf "%f\n")
echo "artifacts-name=${ARTIFACTS_NAME}" >> "$GITHUB_ENV"
- name: Upload artifacts to workflow
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
name: ${{ env.artifacts-name }}
path: ${{ env.build-dir }}/${{ env.artifacts-name }}
retention-days: 1

- name: Upload artifacts to release
if: needs.tag-and-release.outputs.upload_url
- name: Upload artifact to release
if: ${{ !inputs.is-dry-run }}
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5
with:
upload_url: ${{ needs.tag-and-release.outputs.upload_url }}
asset_path: ${{ env.build-dir }}/${{ env.artifacts-name }}
asset_name: ${{ env.artifacts-name }}
asset_content_type: ${{ env.artifacts-content-type }}
upload_url: ${{ steps.release.outputs.upload_url }}
asset_name: ${{ env.artifact-name }}
asset_path: ${{ env.artifact-path }}
asset_content_type: ${{ env.artifact-content-type }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit efc7ef6

Please sign in to comment.