-
Notifications
You must be signed in to change notification settings - Fork 1
103 lines (93 loc) · 3.5 KB
/
build.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
name: Build
on:
push:
jobs:
build: # to work as an action out of the box the ncc-build must be committed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: bahmutov/npm-install@v1
- run: yarn build
- run: git add -f build
- name: Commit build if it changed
run: >
git diff --staged --quiet
|| (git config user.name "github-actions"
&& git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
&& git commit -m "build: autoupdate"
&& echo "buildCommit=$(git rev-parse HEAD)" >>$GITHUB_ENV)
- if: env.buildCommit # skip if the build adds nothing new
name: Push build branch
run: git push -f origin HEAD:build
outputs:
buildCommit: ${{ env.buildCommit }}
verify:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ needs.build.outputs.buildCommit }} # if there is no buildCommit, checkout HEAD
- name: Dry-run
uses: ./
with:
dry: true
debug: true
# if there is a buildCommit, push it back onto the branch that triggered the workflow
- if: needs.build.outputs.buildCommit
id: helper
uses: ph-fritsche/action-helper@master
- if: needs.build.outputs.buildCommit
name: Push back to original branch
run: |
git fetch --depth=2 origin ${{ needs.build.outputs.buildCommit }}
git log --format=oneline -n2 ${{ needs.build.outputs.buildCommit }}
git push -v origin ${{ needs.build.outputs.buildCommit }}:${{ steps.helper.outputs.branchName }}
release:
needs: [build, verify]
if: contains('refs/heads/master,refs/heads/beta,refs/heads/next,refs/heads/alpha', github.ref)
runs-on: ubuntu-latest
steps:
- id: helper
uses: ph-fritsche/action-helper@master
- uses: actions/checkout@v2
with:
ref: ${{ steps.helper.outputs.branchName }}
- name: Ensure branch HEAD did not move
run: |
EXPECTED="${{ needs.build.outputs.buildCommit || github.sha }}"
ACTUAL="$(git rev-parse HEAD)"
if [ $ACTUAL != $EXPECTED ]; then
echo "::error ::HEAD moved to ${ACTUAL} - expected ${EXPECTED}"
exit 1
fi
- id: release
name: Dogfooding release
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add check to the build
uses: actions/github-script@v3
with:
script: |
const [owner, repo] = "${{ github.repository }}".split('/')
const outcome = "${{ steps.release.outcome }}"
const version = "${{ steps.release.outputs.version }}"
const gitTag = "${{ steps.release.outputs.gitTag }}"
const releaseUrl = version ? "https://github.com/${{ github.repository }}/releases/tag/" + gitTag : undefined
const runUrl = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
await github.checks.create({
owner,
repo,
head_sha: "${{ needs.build.outputs.buildCommit || github.sha }}",
name: version ? "release " + version : "release",
conclusion: (outcome === 'success' && !version) ? "skipped" : outcome,
details_url: releaseUrl || runUrl,
output: {
title: "release",
summary: version
? `Released as [${version}](${releaseUrl})`
: "Release skipped",
text: `see ${runUrl}`,
}
})