-
Notifications
You must be signed in to change notification settings - Fork 7
110 lines (94 loc) · 3.66 KB
/
github-actions-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: GitHub Actions - Release
on:
release:
types:
- published
- edited
workflow_run:
workflows:
- GitHub Actions - Create Release
types:
- completed
branches:
- release/actions
jobs:
Setup:
name: Setup and Checks
runs-on: ubuntu-latest
outputs:
release: ${{ steps.set-result.outputs.release }}
steps:
- name: Check tag name or workflow_run conclusion
uses: actions/github-script@v6
with:
script: |
const { payload, eventName } = context;
const tagReg = /^actions-v(0|[1-9]\d*)(\.(0|[1-9]\d*)){2}(-pre)?$/;
const failedWorkflowRun = eventName === 'workflow_run' && payload.workflow_run.conclusion !== 'success';
const mismatchedTagName = eventName === 'release' && ! tagReg.test( payload.release.tag_name );
if ( failedWorkflowRun || mismatchedTagName ) {
await github.rest.actions.cancelWorkflowRun( {
...context.repo,
run_id: context.runId,
} );
}
- name: Get release artifact
id: set-result
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/github-script@v6
with:
script: |
const fs = require( 'fs' );
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts( {
...context.repo,
run_id: context.payload.workflow_run.id,
} );
const artifact = artifacts.find( ( el ) => el.name === 'release' );
const download = await github.rest.actions.downloadArtifact( {
...context.repo,
artifact_id: artifact.id,
archive_format: 'zip',
} );
fs.writeFileSync( `/tmp/release.zip`, Buffer.from( download.data ) );
await exec.exec( 'unzip', [ '/tmp/release.zip', '-d', '/tmp' ] );
const release = fs.readFileSync( `/tmp/release.json`, 'utf8' );
core.setOutput( 'release', release );
UpdateTags:
name: Create Release Build and Update Version Tags
runs-on: ubuntu-latest
needs: Setup
steps:
- name: Resolve tag name
id: resolve-tag
run: |
TAG_NAME="${{ github.event.release.tag_name }}"
if [ "$TAG_NAME" = '' ]; then
TAG_NAME="${{ fromJSON(needs.Setup.outputs.release || '{}').tag_name }}"
fi
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ steps.resolve-tag.outputs.tag_name }}
- name: Prepare node
uses: ./packages/github-actions/actions/prepare-node
with:
node-version: 14
cache-dependency-path: ./packages/github-actions/package-lock.json
install-deps: "no"
- name: Create and commit release build
id: commit-build
run: |
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
TAG_NAME="${{ steps.resolve-tag.outputs.tag_name }}"
.github/scripts/github-actions-create-and-commit-build.sh "$REPO_URL" "$TAG_NAME"
# This `git checkout HEAD^` is to prevent errors from the post jobs like "Prepare node".
git checkout HEAD^ -- ./packages/github-actions/actions
# Set output for the next step
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Update version tags
uses: ./update-version-tags
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ steps.commit-build.outputs.sha }}
release: ${{ needs.Setup.outputs.release }}