-
Notifications
You must be signed in to change notification settings - Fork 33
143 lines (128 loc) · 5.73 KB
/
Copy pathpr-actions.yml
File metadata and controls
143 lines (128 loc) · 5.73 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: PR actions
on:
issue_comment:
types: [created, edited]
jobs:
publish:
name: Publish PR packages
runs-on: ubuntu-latest
environment: test
if: github.event.issue.pull_request && contains(github.event.comment.body, '/publish')
permissions:
id-token: write
pull-requests: write
contents: write
steps:
- name: Check if comment author is a contributor
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
comment_author="${{ github.event.comment.user.login }}"
# Check if user has write access using a different approach
permission=$(gh api repos/${{ github.repository }}/collaborators/$comment_author/permission 2>/dev/null | jq -r '.permission // "none"')
if [[ "$permission" == "admin" || "$permission" == "write" ]]; then
echo "Comment author ($comment_author) has $permission access, continuing"
else
echo "Comment author ($comment_author) has $permission access, skipping job"
exit 1
fi
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ format('refs/pull/{0}/head', github.event.issue.number) }}
path: app-frontend
fetch-depth: 0
- name: install node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '22'
- name: Git author config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Build PR release version
id: build-version
working-directory: app-frontend
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sha=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid' | cut -c1-8)
branch=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName' | sed 's/.*\///')
version=$(git describe --abbrev=0 --tags 2>/dev/null)
version=$(echo $version | cut -d '-' -f 1)
version="$version-pr.${{ github.run_number }}.$branch.$sha"
versionWithoutPrefix=$(echo $version | sed 's/^v//')
git tag -a $version -m "PR release $version"
echo "PR_RELEASE_VERSION=$version" >> $GITHUB_ENV
echo "PR_RELEASE_VERSION=$versionWithoutPrefix" >> $GITHUB_OUTPUT
echo $version
- name: Create PR comment
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
id: pr-comment
with:
issue-number: ${{ github.event.issue.number }}
body: |
## PR release:
* `<link rel="stylesheet" type="text/css" href="https://altinncdn.no/toolkits/altinn-app-frontend/${{ steps.build-version.outputs.PR_RELEASE_VERSION }}/altinn-app-frontend.css">`
* `<script src="https://altinncdn.no/toolkits/altinn-app-frontend/${{ steps.build-version.outputs.PR_RELEASE_VERSION }}/altinn-app-frontend.js"></script>`
> ⚙️ Building...
- name: install dependencies
working-directory: app-frontend
run: yarn --immutable
- name: run build
working-directory: app-frontend
run: yarn build
- name: Azure login
uses: azure/login@532459ea530d8321f2fb9bb10d1e0bcf23869a43 # v3
if: '!env.ACT'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID_FC }}
tenant-id: ${{ secrets.AZURE_TENANT_ID_FC }}
subscription-id: ${{ secrets.AZURE_CDN_SUBSCRIPTION_ID_FC }}
- name: Run release script (pre-release)
working-directory: app-frontend
if: '!env.ACT'
env:
AZCOPY_AUTO_LOGIN_TYPE: AZCLI
AZCOPY_TENANT_ID: ${{ secrets.AZURE_TENANT_ID_FC }}
FD_DOMAIN: ${{ vars.AZURE_DOMAIN_FC }}
FD_ENDPOINT: ${{ vars.AZURE_ENDPOINT_FC }}
FD_PROFILE: ${{ vars.AZURE_PROFILE_FC }}
FD_RESOURCEGROUP: ${{ vars.AZURE_RESOURCE_GROUP_FC }}
run: |
bash .github/scripts/release.sh \
--pre-release \
--azure-sync-cdn \
--azure-sa-name "${{ secrets.PRODUCTION_STORAGEACCOUNT_NAME }}" \
- name: Run sync-index script
working-directory: app-frontend
if: '!env.ACT'
env:
AZCOPY_AUTO_LOGIN_TYPE: AZCLI
AZCOPY_TENANT_ID: ${{ secrets.AZURE_TENANT_ID_FC }}
FD_DOMAIN: ${{ vars.AZURE_DOMAIN_FC }}
FD_ENDPOINT: ${{ vars.AZURE_ENDPOINT_FC }}
FD_PROFILE: ${{ vars.AZURE_PROFILE_FC }}
FD_RESOURCEGROUP: ${{ vars.AZURE_RESOURCE_GROUP_FC }}
run: |
bash .github/scripts/sync-index.sh \
--azure-sync-cdn \
--azure-sa-name "${{ secrets.PRODUCTION_STORAGEACCOUNT_NAME }}" \
- name: Update PR comment - failure
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
if: failure()
with:
issue-number: ${{ github.event.issue.number }}
comment-id: ${{ steps.pr-comment.outputs.comment-id }}
edit-mode: append
body: |
> ❌ Failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Update PR comment - success
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
if: success()
with:
issue-number: ${{ github.event.issue.number }}
comment-id: ${{ steps.pr-comment.outputs.comment-id }}
edit-mode: append
body: |
> ✅ Done!
reactions: rocket