From 9d7fee4ab4fafcf1debf83792bd977a156990824 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Tue, 7 Mar 2023 10:41:27 +0000 Subject: [PATCH] Tag commits on NPM releases with pkgname-v.x.y.z --- .github/workflows/releases.yml | 30 +++++++++++++++++++- .github/workflows/tag-test.yml | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tag-test.yml diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 51649a3e..e35b1985 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -9,11 +9,17 @@ on: jobs: test: + outputs: + sha: ${{ steps.commit.outputs.sha }} + tag: ${{ steps.tag.outputs.tag }} runs-on: macos-latest - steps: - name: setup repo uses: actions/checkout@v3 + - id: commit + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + - id: tag + run: echo "tag=${{ github.event.inputs.package }}-$(cat packages/tool-cache/package.json | jq .version)" >> "$GITHUB_OUTPUT" - name: verify package exists run: ls packages/${{ github.event.inputs.package }} @@ -77,4 +83,26 @@ jobs: curl -X POST -H 'Content-type: application/json' --data '{"text":":dance: Successfully published a new version of ${{ github.event.inputs.package }}"}' $SLACK_WEBHOOK env: SLACK_WEBHOOK: ${{ secrets.SLACK }} + tag: + name: "Tag commit with ${{ github.event.inputs.package }}-version" + runs-on: "macos-latest" + needs: [test, publish] + steps: + - uses: actions/checkout@v3 + - name: Create tag + uses: actions/github-script@v6 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ needs.test.outputs.tag }}', + sha: '${{ needs.test.outputs.sha }}' + }) + - name: notify slack on failure + if: failure() + run: | + curl -X POST -H 'Content-type: application/json' --data '{"text":":pb__failed: Publish of ${{ github.event.inputs.package }} was successful, but failed to tag commit ${{ needs.test.outputs.sha }} with version ${{ needs.test.outputs.tag }}"}' $SLACK_WEBHOOK + env: + SLACK_WEBHOOK: ${{ secrets.SLACK }} diff --git a/.github/workflows/tag-test.yml b/.github/workflows/tag-test.yml new file mode 100644 index 00000000..737627d0 --- /dev/null +++ b/.github/workflows/tag-test.yml @@ -0,0 +1,51 @@ +name: Tag test + +on: + workflow_dispatch: + inputs: + package: + required: true + description: 'core, artifact, cache, exec, github, glob, http-client, io, tool-cache' + +jobs: + test: + outputs: + sha: ${{ steps.commit.outputs.sha }} + tag: ${{ steps.tag.outputs.tag }} + runs-on: macos-latest + steps: + - name: setup repo + uses: actions/checkout@v3 + - id: commit + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + - id: tag + run: echo "tag=${{ github.event.inputs.package }}-$(cat packages/tool-cache/package.json | jq .version)" >> "$GITHUB_OUTPUT" + publish: + runs-on: macos-latest + needs: test + steps: + - name: foo + run: echo "foo" + tag: + name: "Tag commit with ${{ github.event.inputs.package }}-version" + runs-on: "macos-latest" + needs: [test, publish] + steps: + - uses: actions/checkout@v3 + - name: Create tag + uses: actions/github-script@v6 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ needs.test.outputs.tag }}', + sha: '${{ needs.test.outputs.sha }}' + }) + - name: notify slack on failure + # if: failure() + # run: | + # curl -X POST -H 'Content-type: application/json' --data '{"text":":pb__failed: Publish of ${{ github.event.inputs.package }} was successful, but failed to tag commit ${{ needs.test.outputs.sha }} with version ${{ needs.test.outputs.tag }}"}' $SLACK_WEBHOOK + # env: + # SLACK_WEBHOOK: ${{ secrets.SLACK }} +