forked from paritytech/get-fellows-action
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (124 loc) · 4.54 KB
/
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Publish package to GitHub Packages
on:
push:
branches:
- main
pull_request:
env:
IMAGE_NAME: action
REGISTRY: ghcr.io
jobs:
test-image:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Check that the image builds
run: docker build . --file Dockerfile
validate-action:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/[email protected]
# This checks that .github/workflows/review-bot.yml is pointing towards the main branch
# as, during development, we change this to use the code from the test branch and
# we may forget to set it back to main
- name: Validate that action points to main branch
run: |
BRANCH=$(yq '.jobs.review-approvals.steps[1].uses' $FILE_NAME | cut -d "@" -f2)
# If the branch is not the main branch
if [ "$BRANCH" != "$GITHUB_BASE_REF" ]; then
echo "Action points to $BRANCH. It has to point to $GITHUB_BASE_REF instead!"
exit 1
else
echo "Action is correctly pointing to $GITHUB_BASE_REF"
fi
env:
FILE_NAME: ".github/workflows/review-bot.yml"
test-versions:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.verification.outputs.VERSION }}
steps:
- uses: actions/[email protected]
- name: Extract package.json version
id: package_version
run: echo "VERSION=$(jq '.version' -r package.json)" >> $GITHUB_OUTPUT
- name: Compare versions
id: verification
uses: Bullrich/compare-version-on-action@main
with:
version: ${{ steps.package_version.outputs.VERSION }}
tag:
if: github.event_name == 'push' && needs.test-versions.outputs.version != ''
# needs: [test-image, test-versions]
needs: [test-versions]
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
tagExists: ${{ steps.checkTag.outputs.exists }}
steps:
- uses: mukunku/[email protected]
id: checkTag
with:
tag: v${{ needs.test-versions.outputs.version }}
- uses: actions/[email protected]
- name: Tag version and create release
if: steps.checkTag.outputs.exists == 'false'
run: gh release create $VERSION --generate-notes
env:
VERSION: ${{ needs.test-versions.outputs.version }}
GH_TOKEN: ${{ github.token }}
publish:
runs-on: ubuntu-latest
permissions:
packages: write
# !Undo this
needs: [test-versions]
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- run: echo "Tags are $tags and labels are $labels"
env:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# - uses: actions/checkout@v3
# - name: Build image
# run: docker build . --file Dockerfile --label "version=$TAG" --tag $IMAGE_NAME
# env:
# TAG: v${{ needs.test-versions.outputs.version }}
# - name: Log into registry
# run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
# - name: Push image
# run: |
# IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# # Change all uppercase to lowercase
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# # Strip git ref prefix from version
# VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# # Strip "v" prefix from tag name
# [[ ! -z $TAG ]] && VERSION=$(echo $TAG | sed -e 's/^v//')
# # Use Docker `latest` tag convention
# [ "$VERSION" == "main" ] && VERSION=latest
# echo IMAGE_ID=$IMAGE_ID
# echo VERSION=$VERSION
# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
# docker push $IMAGE_ID:$VERSION
# env:
# TAG: v${{ needs.test-versions.outputs.version }}