From 67955872b6d7aaff54625de8df03ce0db26c82e5 Mon Sep 17 00:00:00 2001 From: Ethan Knapp Date: Sat, 3 Feb 2024 13:18:21 -0700 Subject: [PATCH] update CI --- .github/workflows/auto_release.yml | 26 --------- .../{publish_builds.yml => release.yml} | 55 +++++++++++++++++-- package.json | 2 +- script/generate_tags.py | 28 +++++++++- 4 files changed, 75 insertions(+), 36 deletions(-) delete mode 100644 .github/workflows/auto_release.yml rename .github/workflows/{publish_builds.yml => release.yml} (62%) diff --git a/.github/workflows/auto_release.yml b/.github/workflows/auto_release.yml deleted file mode 100644 index 000d616..0000000 --- a/.github/workflows/auto_release.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Auto Release -on: - push: - branches: - - master - paths: - - 'package.json' - -permissions: - contents: write - -jobs: - build: - name: Release - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Release - uses: justincy/github-action-npm-release@2.0.2 - id: release - - name: Print release output - if: ${{ steps.release.outputs.released == 'true' }} - run: echo Release ID ${{ steps.release.outputs.release_id }} \ No newline at end of file diff --git a/.github/workflows/publish_builds.yml b/.github/workflows/release.yml similarity index 62% rename from .github/workflows/publish_builds.yml rename to .github/workflows/release.yml index a5c8a78..276dca7 100644 --- a/.github/workflows/publish_builds.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,5 @@ --- -name: Publish Images +name: Publish Images and Release # yamllint disable-line rule:truthy on: @@ -67,10 +67,25 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - id: check + uses: EndBug/version-check@v2 + + with: + diff-search: true + token: ${{ secrets.GITHUB_TOKEN }} + + # You can use this to make the action use the current version (either from the + # local file or the provided URL, see the `file-url` option) as either the added + # or deleted version. + # Accepted values are 'new' (if you want that version to be the "added" one) and + # 'old' (to make it the "deleted" one). + # Default: '' + # assume-same-version: old + - name: Generate short tags id: tags run: | - script/generate_tags.py + script/generate_tags.py --package-version ${{ steps.check.outputs.version }} --package-version-changed ${{ steps.check.outputs.changed }} # --suffix "${{ matrix.image.suffix }}" - name: Build and push @@ -91,10 +106,38 @@ jobs: BUILD_VERSION=${{ steps.tags.outputs.version }} BUILD_CHANNEL=${{ steps.tags.outputs.channel }} + outputs: + version: ${{ steps.tags.outputs.version }} + channel: ${{ steps.tags.outputs.channel }} + + create-release: + if: github.repository == 'matchlighter/typedaemon' && github.event_name != 'release' && needs.deploy-docker.outputs.channel == 'release' + needs: [deploy-docker] + permissions: + contents: write + packages: write + runs-on: ubuntu-latest + steps: + - name: "Generate changelog" + id: changelog + uses: heinrichreimer/action-github-changelog-generator@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + body: ${{ steps.changelog.outputs.changelog }} + tag_name: ${{ needs.deploy-docker.outputs.version }} + target_commitish: ${{ github.ref }} + + outputs: + body: ${{ steps.changelog.outputs.changelog }} + deploy-ha-addon-repo: - if: github.repository == 'matchlighter/typedaemon' && github.event_name == 'release' + if: ${{ !failure() && github.repository == 'matchlighter/typedaemon' && needs.deploy-docker.outputs.channel == 'release' }} runs-on: ubuntu-latest - needs: [deploy-docker] + needs: [deploy-docker, create-release] steps: - name: Trigger Workflow uses: actions/github-script@v6 @@ -107,7 +150,7 @@ jobs: workflow_id: "bump-version.yml", ref: "master", inputs: { - version: "${{ github.event.release.tag_name }}", - content: ${{ toJSON(github.event.release.body) }} + version: "${{ needs.deploy-docker.outputs.version }}", + content: ${{ toJSON(github.event.release.body || needs.create-release.outputs.body) }} } }) diff --git a/package.json b/package.json index 6517213..b84e536 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typedaemon", - "version": "0.3.2", + "version": "0.3.3", "license": "MIT", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/script/generate_tags.py b/script/generate_tags.py index 1a22ab0..d827318 100755 --- a/script/generate_tags.py +++ b/script/generate_tags.py @@ -16,8 +16,21 @@ required=False, help="The suffix of the tag.", ) +parser.add_argument( + "--package-version", + type=str, + required=False, +) +parser.add_argument( + "--package-version-changed", + type=str, + required=False, +) +def package_json_version_changed(): + pass + def main(): args = parser.parse_args() @@ -25,8 +38,13 @@ def main(): version = "" major_minor_version = None tags_to_push = [] - if os.environ.get("GITHUB_EVENT_NAME", None) == "release": - version = os.environ.get("GITHUB_REF").replace("refs/tags/", "") + + branch = os.environ.get("GITHUB_REF", "arbitrary").replace("refs/heads/", "") + + def set_version(v): + nonlocal version, channel, major_minor_version + + version = v tags_to_push.append(version) # detect channel from tag @@ -39,8 +57,12 @@ def main(): channel = CHANNEL_RELEASE else: channel = CHANNEL_BETA + + if os.environ.get("GITHUB_EVENT_NAME", None) == "release": + set_version(os.environ.get("GITHUB_REF").replace("refs/tags/", "")) + elif branch == "master" and args.package_version_changed == "true": + set_version(args.package_version) else: - branch = os.environ.get("GITHUB_REF", "arbitrary").replace("refs/heads/", "") sha = os.environ.get("GITHUB_SHA", "") datecode = datetime.datetime.now().isoformat() version = f"{branch}-{sha}-{datecode}"